blob: b552e528680491bba3d3eb79d431407b9680ae2f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
package model.asn1;
import model.asn1.exceptions.ParseException;
import model.asn1.parsing.BytesReader;
/**
* Represents the ASN.1 OCTET STRING type. An OCTET STRING is just a sequence of bytes.
*/
public class OctetString extends ASN1Object {
/**
* The X.680 universal class tag assignment.
*/
public static final Tag TAG = new Tag(TagClass.UNIVERSAL, false, 0x4);
private final Byte[] bytes;
/**
* EFFECTS: Initiate the OctetString object with the given bytes array. The byte array can be arbitrary.
* REQUIRES: For the requirements of tag and parentTag, consult {@link ASN1Object}.
*/
public OctetString(Tag tag, Tag parentTag, Byte[] bytes) {
super(tag, parentTag);
this.bytes = bytes;
}
/**
* EFFECTS: Parse tags and value from user input. Tags are parsed as-per {@link ASN1Object}.
* Throws {@link ParseException} if the encoded data is invalid, see {@link ASN1Object}.
* MODIFIES: this, encoded
*/
public OctetString(BytesReader encoded, boolean hasParentTag) throws ParseException {
super(encoded, hasParentTag);
this.bytes = encoded.require(getLength(), true);
}
/**
* EFFECTS: Get the value bytes ready to encode into DER.
*/
@Override
public Byte[] encodeValueDER() {
return bytes;
}
public Byte[] getBytes() {
return bytes;
}
}
|