1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package net.sf.michaelo.tomcat.pac;
17
18 import java.util.Objects;
19
20
21
22
23
24
25 public class PacSignatureData {
26
27 public enum SignatureType {
28 HMAC_MD5(-138, 16, 23),
29 HMAC_SHA1_96_AES128(15, 12, 17),
30 HMAC_SHA1_96_AES256(16, 12, 18);
31
32 private final int value;
33 private final int size;
34 private final int eType;
35
36 SignatureType(int value, int size, int eType) {
37 this.value = value;
38 this.size = size;
39 this.eType = eType;
40 }
41
42 public int getValue() {
43 return value;
44 }
45
46 public int getSize() {
47 return size;
48 }
49
50 public int getEType() {
51 return eType;
52 }
53 }
54
55 private final SignatureType type;
56 private final byte[] signature;
57
58
59
60
61
62
63
64
65
66 public PacSignatureData(byte[] sigDataBytes) {
67 Objects.requireNonNull(sigDataBytes, "sigDataBytes cannot be null");
68 if (sigDataBytes.length == 0) throw new IllegalArgumentException("sigDataBytes cannot be empty");
69
70 PacDataBuffer buf = new PacDataBuffer(sigDataBytes);
71
72
73 int type = buf.getInt();
74 if (type == SignatureType.HMAC_MD5.getValue()) {
75 this.type = SignatureType.HMAC_MD5;
76 } else if (type == SignatureType.HMAC_SHA1_96_AES128.getValue()) {
77 this.type = SignatureType.HMAC_SHA1_96_AES128;
78 } else if (type == SignatureType.HMAC_SHA1_96_AES256.getValue()) {
79 this.type = SignatureType.HMAC_SHA1_96_AES256;
80 } else {
81 throw new IllegalArgumentException("Unsupported signature type " + type);
82 }
83
84
85 this.signature = new byte[this.type.getSize()];
86 buf.get(this.signature);
87
88
89 }
90
91 public SignatureType getType() {
92 return type;
93 }
94
95 public byte[] getSignature() {
96 return signature;
97 }
98 }