~ubuntu-branches/ubuntu/trusty/rhash/trusty

« back to all changes in this revision

Viewing changes to bindings/java/src/org/sf/rhash/HashType.java

  • Committer: Package Import Robot
  • Author(s): Aleksey Kravchenko
  • Date: 2011-09-14 23:50:14 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: package-import@ubuntu.com-20110914235014-m9mk3eg7e6rah17x
Tags: 1.2.8-1
* New upstream release version 1.2.8
 - language bindings for Java, Perl, Python, Ruby
 - Russian translation
 - fixed recommended libssl1.0.0 dependency
 - patched broken re-compilation
 - fixed a mistype in perl documentation
 - control: updated Vcs-Git field
 - copyright: corrected Format field, added Upstream-Contact
 - copyright: updated Copyright field, mentioned another developer

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * This file is a part of Java Bindings for Librhash
 
3
 * Copyright (c) 2011, Sergey Basalaev <sbasalaev@gmail.com>
 
4
 * Librhash is (c) 2011, Alexey S Kravchenko <rhash.admin@gmail.com>
 
5
 * 
 
6
 * Permission is hereby granted, free of charge,  to any person obtaining a copy
 
7
 * of this software and associated documentation files (the "Software"), to deal
 
8
 * in the Software without restriction,  including without limitation the rights
 
9
 * to  use,  copy,  modify,  merge, publish, distribute, sublicense, and/or sell
 
10
 * copies  of  the Software,  and  to permit  persons  to whom  the Software  is
 
11
 * furnished to do so.
 
12
 * 
 
13
 * This library  is distributed  in the hope that it will be useful, but WITHOUT
 
14
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 
15
 * FOR A PARTICULAR PURPOSE. Use it at your own risk!
 
16
 */
 
17
 
 
18
package org.sf.rhash;
 
19
 
 
20
/**
 
21
 * Type of hashing algorithm.
 
22
 * Supported algorithms are MD4, MD5, SHA1/SHA2, Tiger,
 
23
 * DC++ TTH, BitTorrent BTIH, AICH, EDonkey 2000 hash, GOST R 34.11-94,
 
24
 * RIPEMD-160, HAS-160, EDON-R 256/512, Whirlpool and Snefru-128/256.
 
25
 */
 
26
public enum HashType {
 
27
        /** CRC32 checksum. */
 
28
        CRC32(1),
 
29
        /** MD4 hash. */
 
30
        MD4(1 << 1),
 
31
        /** MD5 hash. */
 
32
        MD5(1 << 2),
 
33
        /** SHA-1 hash. */
 
34
        SHA1(1 << 3),
 
35
        /** Tiger hash. */
 
36
        TIGER(1 << 4),
 
37
        /** Tiger tree hash */
 
38
        TTH(1 << 5),
 
39
        /** BitTorrent info hash. */
 
40
        BTIH(1 << 6),
 
41
        /** EDonkey 2000 hash. */
 
42
        ED2K(1 << 7),
 
43
        /** eMule AICH. */
 
44
        AICH(1 << 8),
 
45
        /** Whirlpool hash. */
 
46
        WHIRLPOOL(1 << 9),
 
47
        /** RIPEMD-160 hash. */
 
48
        RIPEMD160(1 << 10),
 
49
        /** GOST R 34.11-94. */
 
50
        GOST(1 << 11),
 
51
        GOST_CRYPTOPRO(1 << 12),
 
52
        /** HAS-160 hash. */
 
53
        HAS160(1 << 13),
 
54
        /** Snefru-128 hash. */
 
55
        SNEFRU128(1 << 14),
 
56
        /** Snefru-256 hash. */
 
57
        SNEFRU256(1 << 15),
 
58
        /** SHA-224 hash. */
 
59
        SHA224(1 << 16),
 
60
        /** SHA-256 hash. */
 
61
        SHA256(1 << 17),
 
62
        /** SHA-384 hash. */
 
63
        SHA384(1 << 18),
 
64
        /** SHA-512 hash. */
 
65
        SHA512(1 << 19),
 
66
        /** EDON-R 256. */
 
67
        EDONR256(1 << 20),
 
68
        /** EDON-R 512. */
 
69
        EDONR512(1 << 21);
 
70
 
 
71
        /** hash_id for the native API */
 
72
    private int hashId;
 
73
 
 
74
    /**
 
75
     * Construct HashType for specified native hash_id
 
76
     * @param hashId hash identifier for native API
 
77
     */
 
78
    private HashType(int hashId) {
 
79
        this.hashId = hashId;
 
80
    }
 
81
 
 
82
        /**
 
83
         * Returns hash_id for the native API.
 
84
     * @return hash identifier
 
85
     */
 
86
        int hashId() {
 
87
            return hashId;
 
88
        }
 
89
 
 
90
        /**
 
91
         * Returns lowest <code>HashType</code> for given id mask.
 
92
         * Used by <code>RHash.getDigest()</code>.
 
93
         * @param flags  mask of hash identifiers
 
94
         * @return  <code>HashType</code> object or <code>null</code>
 
95
         *   if no <code>HashType</code> for given mask exists
 
96
         */
 
97
        static HashType forHashFlags(int flags) {
 
98
                if (flags == 0) return null;
 
99
                int lowest = 0;
 
100
                while ((flags % 2) == 0) {
 
101
                        flags >>>= 1;
 
102
                        lowest++;
 
103
                }
 
104
                for (HashType t : HashType.values()) {
 
105
                        if (t.hashId == (1 << lowest)) return t;
 
106
                }
 
107
                return null;
 
108
        }
 
109
 
 
110
        /**
 
111
         * Returns size of binary digest for this type.
 
112
         * @return size of binary digest, in bytes
 
113
         */
 
114
        public int getDigestSize() {
 
115
                //TODO: rhash_get_digest_size
 
116
                return -1;
 
117
        }
 
118
}