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.transport.http;
20
21 import javax.inject.Named;
22 import javax.inject.Singleton;
23
24 import java.util.HashMap;
25 import java.util.Map;
26 import java.util.function.Function;
27
28 import org.eclipse.aether.internal.impl.checksum.Md5ChecksumAlgorithmFactory;
29 import org.eclipse.aether.internal.impl.checksum.Sha1ChecksumAlgorithmFactory;
30 import org.eclipse.aether.spi.connector.transport.http.ChecksumExtractorStrategy;
31
32
33
34
35 @Singleton
36 @Named(XChecksumExtractor.NAME)
37 public final class XChecksumExtractor extends ChecksumExtractorStrategy {
38 public static final String NAME = "xChecksum";
39
40 @Override
41 public Map<String, String> extractChecksums(Function<String, String> headerGetter) {
42 String value;
43 HashMap<String, String> result = new HashMap<>();
44
45 value = headerGetter.apply("x-checksum-sha1");
46 if (value != null) {
47 result.put(Sha1ChecksumAlgorithmFactory.NAME, value);
48 }
49
50 value = headerGetter.apply("x-checksum-md5");
51 if (value != null) {
52 result.put(Md5ChecksumAlgorithmFactory.NAME, value);
53 }
54 if (!result.isEmpty()) {
55 return result;
56 }
57
58 value = headerGetter.apply("x-goog-meta-checksum-sha1");
59 if (value != null) {
60 result.put(Sha1ChecksumAlgorithmFactory.NAME, value);
61 }
62
63 value = headerGetter.apply("x-goog-meta-checksum-md5");
64 if (value != null) {
65 result.put(Md5ChecksumAlgorithmFactory.NAME, value);
66 }
67 return result.isEmpty() ? null : result;
68 }
69 }