• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

evolvedbinary / elemental / 982

29 Apr 2025 08:34PM UTC coverage: 56.409% (+0.007%) from 56.402%
982

push

circleci

adamretter
[feature] Improve README.md badges

28451 of 55847 branches covered (50.94%)

Branch coverage included in aggregate %.

77468 of 131924 relevant lines covered (58.72%)

0.59 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

73.81
/exist-core/src/main/java/org/exist/util/crypto/digest/DigestType.java
1
/*
2
 * Elemental
3
 * Copyright (C) 2024, Evolved Binary Ltd
4
 *
5
 * admin@evolvedbinary.com
6
 * https://www.evolvedbinary.com | https://www.elemental.xyz
7
 *
8
 * Use of this software is governed by the Business Source License 1.1
9
 * included in the LICENSE file and at www.mariadb.com/bsl11.
10
 *
11
 * Change Date: 2028-04-27
12
 *
13
 * On the date above, in accordance with the Business Source License, use
14
 * of this software will be governed by the Apache License, Version 2.0.
15
 *
16
 * Additional Use Grant: Production use of the Licensed Work for a permitted
17
 * purpose. A Permitted Purpose is any purpose other than a Competing Use.
18
 * A Competing Use means making the Software available to others in a commercial
19
 * product or service that: substitutes for the Software; substitutes for any
20
 * other product or service we offer using the Software that exists as of the
21
 * date we make the Software available; or offers the same or substantially
22
 * similar functionality as the Software.
23
 */
24
package org.exist.util.crypto.digest;
25

26
import java.util.function.Supplier;
27

28
/**
29
 * An enumeration of message digest types.
30
 *
31
 * @author <a href="mailto:adam@evolvedbinary.com">Adam Retter</a>
32
 */
33
public enum DigestType {
1✔
34
    MD_2((byte)0x01, 128, MD2StreamableDigest::new, "MD2"),
1✔
35
    MD_4((byte)0x02, 128, MD4StreamableDigest::new, "MD4"),
1✔
36
    MD_5((byte)0x03, 128, MD5StreamableDigest::new, "MD5"),
1✔
37

38
    SHA_1(  (byte)0x10,  160, SHA1StreamableDigest::new, "SHA-1"),
1✔
39
    SHA_256((byte)0x11,  256, SHA256StreamableDigest::new, "SHA-256"),
1✔
40
    SHA_512((byte)0x12, 512, SHA512StreamableDigest::new, "SHA-512"),
1✔
41

42
    RIPEMD_160((byte)0x20, 160, RIPEMD160StreamableDigest::new, "RIPEMD-160", "RIPEMD160"),
1✔
43
    RIPEMD_256((byte)0x21, 256, RIPEMD256StreamableDigest::new, "RIPEMD-256", "RIPEMD256"),
1✔
44

45
    BLAKE_160((byte)0x30, 160, Blake160StreamableDigest::new, "BLAKE2B-160", "BLAKE-160"),
1✔
46
    BLAKE_256((byte)0x31, 256, Blake256StreamableDigest::new, "BLAKE2B-256", "BLAKE-256"),
1✔
47
    BLAKE_512((byte)0x31, 512, Blake512StreamableDigest::new, "BLAKE2B-512", "BLAKE-512");
1✔
48

49

50
    private final byte id;
51
    private final int bits;
52
    private final Supplier<StreamableDigest> streamableFactory;
53
    private final String[] commonNames;
54

55
    DigestType(final byte id, final int bits, final Supplier<StreamableDigest> streamableFactory, final String... commonNames) {
1✔
56
        this.id = id;
1✔
57
        this.bits = bits;
1✔
58
        this.streamableFactory = streamableFactory;
1✔
59
        this.commonNames = commonNames;
1✔
60
    }
1✔
61

62
    /**
63
     * Get the id of the message digest.
64
     *
65
     * @return the id of the message digest
66
     */
67
    public byte getId() {
68
        return id;
×
69
    }
70

71
    /**
72
     * Get the digest type by id.
73
     *
74
     * @param id the id of the digest type
75
     *
76
     * @return the digest type
77
     *
78
     * @throws IllegalArgumentException if the id is invalid.
79
     */
80
    public static DigestType forId(final byte id) {
81
        for (final DigestType digestType : values()) {
×
82
            if (id == digestType.getId()) {
×
83
                return digestType;
×
84
            }
85
        }
86
        throw new IllegalArgumentException("Unknown digest type id: " + id);
×
87
    }
88

89
    /**
90
     * Get the common names for the digest type.
91
     *
92
     * @return the common names.
93
     */
94
    public String[] getCommonNames() {
95
        return commonNames;
1✔
96
    }
97

98
    /**
99
     * Get the digest type by common name.
100
     *
101
     * @param commonName the common name of the digest type
102
     *
103
     * @return the digest type
104
     *
105
     * @throws IllegalArgumentException if the common name is invalid.
106
     */
107
    public static DigestType forCommonName(final String commonName) {
108
        for (final DigestType digestType : values()) {
1!
109
            for (final String cn : digestType.commonNames) {
1✔
110
                if (cn.equals(commonName)) {
1✔
111
                    return digestType;
1✔
112
                }
113
            }
114
        }
115

116
        throw new IllegalArgumentException("Unknown digest type common name: " + commonName);
×
117
    }
118

119
    /***
120
     * The length of the generated message digest
121
     *
122
     * @return the message digest length in bits
123
     */
124
    public int getDigestLength() {
125
        return bits;
1✔
126
    }
127

128
    /***
129
     * The length of the generated message digest
130
     *
131
     * @return the message digest length in bytes
132
     */
133
    public int getDigestLengthBytes() {
134
        return bits / 8;
1✔
135
    }
136

137
    public StreamableDigest newStreamableDigest() {
138
        return streamableFactory.get();
1✔
139
    }
140
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc