diff options
author | Yuuta Liang <yuutaw@students.cs.ubc.ca> | 2023-10-12 12:10:33 +0800 |
---|---|---|
committer | Yuuta Liang <yuutaw@students.cs.ubc.ca> | 2023-10-12 12:10:33 +0800 |
commit | d342a45d98c4795b3a3fe1aaef5236ad4a782b55 (patch) | |
tree | f4ebc0ad962b138d9371413fcc71c97a559df506 /src/main/model/asn1/UTF8String.java | |
parent | e60c9c76243cfe0a408af98dc60bedb973e815db (diff) | |
download | jca-d342a45d98c4795b3a3fe1aaef5236ad4a782b55.tar jca-d342a45d98c4795b3a3fe1aaef5236ad4a782b55.tar.gz jca-d342a45d98c4795b3a3fe1aaef5236ad4a782b55.tar.bz2 jca-d342a45d98c4795b3a3fe1aaef5236ad4a782b55.zip |
Implement data structures from X.680, X.501, X.509, and PKCS#10, with X.690 encoding / decoding support
The implementation took four days, and it is still a little bit rough. Updated version should arrive soon.
Signed-off-by: Yuuta Liang <yuutaw@students.cs.ubc.ca>
Diffstat (limited to 'src/main/model/asn1/UTF8String.java')
-rw-r--r-- | src/main/model/asn1/UTF8String.java | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/src/main/model/asn1/UTF8String.java b/src/main/model/asn1/UTF8String.java new file mode 100644 index 0000000..e6b101e --- /dev/null +++ b/src/main/model/asn1/UTF8String.java @@ -0,0 +1,40 @@ +package model.asn1; + +import model.asn1.exceptions.ParseException; +import model.asn1.parsing.BytesReader; +import ui.Utils; + +import java.nio.charset.StandardCharsets; +import java.util.Arrays; + +/** + * Represents an ASN.1 UTF8String type. It accepts any UTF-8 chars. Because UTF-8 character set is large and its chars + * have variable width, this implementation does not validate against legal UTF-8 characters. + */ +public class UTF8String extends ASN1String { + /** + * The X.680 universal class tag assignment. + */ + public static final Tag TAG = new Tag(TagClass.UNIVERSAL, false, 0x0C); + + /** + * EFFECTS: Constructs a UTF8String with the given tag and string. + * Throws {@link ParseException} if the string is illegal. + * REQUIRES: For the requirements of tag and parentTag, consult {@link ASN1Object}. + */ + public UTF8String(Tag tag, Tag parentTag, String string) throws ParseException { + super(tag, parentTag, string); + } + + /** + * EFFECTS: Parse from user input. Tags are parsed as-per {@link ASN1Object}. The value will be parsed as UTF-8 big + * endian. + * Throws {@link ParseException} if the encoded data is invalid. + * MODIFIES: this, encoded + */ + public UTF8String(BytesReader encoded, boolean hasParentTag) throws ParseException, IllegalArgumentException { + super(encoded, hasParentTag); + setString(new String(Utils.byteToByte(encoded.require(getLength(), true)), + StandardCharsets.UTF_8)); + } +} |