1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.eclipse.aether.internal.impl.checksum;
20
21 import java.nio.ByteBuffer;
22 import java.security.MessageDigest;
23 import java.security.NoSuchAlgorithmException;
24
25 import org.eclipse.aether.spi.connector.checksum.ChecksumAlgorithm;
26 import org.eclipse.aether.spi.connector.checksum.ChecksumAlgorithmFactory;
27 import org.eclipse.aether.spi.connector.checksum.ChecksumAlgorithmFactorySupport;
28 import org.eclipse.aether.util.StringDigestUtil;
29
30
31
32
33
34
35 public abstract class MessageDigestChecksumAlgorithmFactorySupport extends ChecksumAlgorithmFactorySupport {
36 public MessageDigestChecksumAlgorithmFactorySupport(String name, String extension) {
37 super(name, extension);
38 }
39
40 @Override
41 public ChecksumAlgorithm getAlgorithm() {
42 try {
43 MessageDigest messageDigest = MessageDigest.getInstance(getName());
44 return new ChecksumAlgorithm() {
45 @Override
46 public void update(final ByteBuffer input) {
47 messageDigest.update(input);
48 }
49
50 @Override
51 public String checksum() {
52 return StringDigestUtil.toHexString(messageDigest.digest());
53 }
54 };
55 } catch (NoSuchAlgorithmException e) {
56 throw new IllegalStateException(
57 "MessageDigest algorithm " + getName() + " not supported, but is required by resolver.", e);
58 }
59 }
60 }