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  
29  		HMAC_MD5(-138, 16, 23), HMAC_SHA1_96_AES128(15, 12, 17), HMAC_SHA1_96_AES256(16, 12, 18);
30  
31  		private final int value;
32  		private final int size;
33  		private final int eType;
34  
35  		SignatureType(int value, int size, int eType) {
36  			this.value = value;
37  			this.size = size;
38  			this.eType = eType;
39  		}
40  
41  		public int getValue() {
42  			return value;
43  		}
44  
45  		public int getSize() {
46  			return size;
47  		}
48  
49  		public int getEType() {
50  			return eType;
51  		}
52  	}
53  
54  	private final SignatureType type;
55  	private final byte[] signature;
56  
57  	
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  	public PacSignatureData(byte[] sigDataBytes) {
70  		Objects.requireNonNull(sigDataBytes, "sigDataBytes cannot be null");
71  		if (sigDataBytes.length == 0)
72  			throw new IllegalArgumentException("sigDataBytes cannot be empty");
73  
74  		PacDataBuffer buf = new PacDataBuffer(sigDataBytes);
75  
76  		
77  		int type = buf.getInt();
78  		if (type == SignatureType.HMAC_MD5.getValue()) {
79  			this.type = SignatureType.HMAC_MD5;
80  		} else if (type == SignatureType.HMAC_SHA1_96_AES128.getValue()) {
81  			this.type = SignatureType.HMAC_SHA1_96_AES128;
82  		} else if (type == SignatureType.HMAC_SHA1_96_AES256.getValue()) {
83  			this.type = SignatureType.HMAC_SHA1_96_AES256;
84  		} else {
85  			throw new IllegalArgumentException("Unsupported signature type " + type);
86  		}
87  
88  		
89  		this.signature = new byte[this.type.getSize()];
90  		buf.get(this.signature);
91  
92  		
93  	}
94  
95  	public SignatureType getType() {
96  		return type;
97  	}
98  
99  	public byte[] getSignature() {
100 		return signature;
101 	}
102 
103 }