This module contains support to encode and decode ASN.1 values.
Encoding is done using the DER (distinguished encoding rules) to ensure a unique encoded represenation.
Decoding is done using the BER to accept a wider range of input.
If the data to encode is not in canonical form (that is, if it
violates the DER, that is signalled via the GenericAsn1Value.violatesDer
flag on the decoded object.
A specific custom ASN.1 type is typically implemented using this module by implementing
Asn1Value
subclass, which will be most likely a subclass of
Asn1Sequence
, Asn1SequenceOf
or Asn1SetOf
Decoder
subclass using the decodeSequence, decodeSequenceOf or decodeSetOf function.Packages | |
de.dlkw.asn1 | Encoding and decoding of (several) standard ASN.1 types. |
Dependencies | ||
ceylon.buffer | 1.2.2 | |
ceylon.collection | 1.2.2 | |
ceylon.time | 1.2.2 | |
ceylon.whole | 1.2.2 |
Encoding and decoding of (several) standard ASN.1 types.
Functions | |
asn1Boolean | shared Asn1Boolean asn1Boolean(Boolean val, Tag tag = ...) Creates an Asn1Boolean. Parameters:
|
asn1Integer | shared Asn1Integer asn1Integer(Integer valu, Tag tag = ...) Creates an ASN.1 INTEGER value, implemented by Parameters:
|
asn1Null | shared Asn1Null asn1Null(Tag tag = ...) Creates an Asn1Null value. Parameters:
|
asn1Sequence | shared Asn1Sequence<Types>|EncodingError asn1Sequence<Types>(Types elements, [Asn1Value<Anything>|Option+] defaults, Tag tag = ...) Creates an Asn1Sequence. If an element with a default value is passed in as Parameters:
|
asn1SequenceOf | shared Asn1SequenceOf<Inner> asn1SequenceOf<Inner>(Inner[] elements, Tag tag = ...) Creates an Asn1SequenceOf. Using different tags on the elements might not make sense in ASN.1. I don't know now. It is the user's responsibility that the elements all have the same tag, then. Parameters:
|
asn1Set | shared Asn1Set<Types>|EncodingError asn1Set<Types>(Types elements, [Asn1Value<Anything>|Option+] defaults, Tag tag = ...) Creates an Asn1Set. This is a difficult and confusing ASN.1 concept. Do not write ASN.1 specifications that use SET, use SEQUENCE instead! Decoding is not yet supported. The attribute Parameters:
|
asn1SetOf | shared Asn1SetOf<Inner>|EncodingError asn1SetOf<Inner>(Inner[] elements, Tag tag = ...) Creates an Asn1SetOf. Using different tags on the elements might not make sense in ASN.1. I don't know now. It is the user's responsibility that the elements all have the same tag, then. The attribute Parameters:
|
asn1Whole | shared Asn1Whole asn1Whole(Whole valu, Tag tag = ...) Creates an ASN.1 INTEGER value, implemented by Parameters:
|
bitStringFromBytes | shared BitString|EncodingError bitStringFromBytes(Byte[] bytes, Integer numberOfBits = ..., Tag tag = ...) Creates a BitString. Parameters:
|
decodeIdentityOctets | shared [IdentityInfo, Integer]|DecodingError decodeIdentityOctets(Byte[] input, Integer offset = 0) Decodes the identity octets of a BER encoded ASN.1 value. Returns identity octets information and pos of first octet after identity octets Parameters:
|
decodeLengthOctets | shared [Integer, Integer, Boolean]|DecodingError decodeLengthOctets(Byte[] input, Integer offset) Decodes the length octets of a BER encoded ASN.1 value. Returns the decoded length, the position of the first octet in Parameters:
|
encodeAsn1Sequence | shared [Byte[], IdentityInfo, Integer, Integer]|EncodingError encodeAsn1Sequence(Asn1Value<Anything>?[] elements, <Asn1Value<Anything>|Option>[] defaults, Tag tag) Encodes an ASN.1 SEQUENCE. Returns the encoded octets, the identity octets info, the offset of the length octets in the encoded octets, and the the offset of the contents octets. If a mandatory element is not given (null), then an EncodingError is returned. Parameters:
|
encodeLength | shared [Byte+] encodeLength(Integer length) Encodes the length octets. Parameters:
|
generalizedTimeFromInstant | shared GeneralizedTime|EncodingError generalizedTimeFromInstant(Instant instant, Tag tag = ...) Creates a GeneralizedTime from an Parameters:
|
generalizedTimeFromString | shared GeneralizedTime|EncodingError generalizedTimeFromString(String stringValue, Tag tag = ...) Creates a GeneralizedTime from a Parameters:
|
hexdigits | shared String hexdigits(Byte b) Formats a Byte as a two-digit hexadecimal number. |
hexdump | shared String hexdump({Byte*} bytes) Format a Byte sequence as a sequence of two-digit hexadecimal numbers, separated by a space. |
ia5String | shared IA5String|EncodingError ia5String(String val, Tag tag = ...) Creates an ASN.1 IA5String. Returns an error if Parameters:
|
objectIdentifier | shared ObjectIdentifier objectIdentifier(Integer[] parts, Tag tag = ...) Creates an ObjectIdentifier. Parameters:
|
octetString | shared OctetString octetString(Byte[] val, Tag tag = ...) Creates an OctetString. Parameters:
|
printableString | shared PrintableString|EncodingError printableString(String val, Tag tag = ...) Creates an ASN.1 PrintableString. Returns an error if Parameters:
|
taggedValue | shared TaggedValue<Type> taggedValue<Type>(Type wrapped, Tag tag) Creates a TaggedValue, wrapping an ASN.1 value with an explicit tag. Parameters:
|
utcTimeFromInstant | shared UTCTime|EncodingError utcTimeFromInstant(Instant instant, Tag tag = ...) Creates a UTCTime from an Parameters:
|
utcTimeFromString | shared UTCTime|EncodingError utcTimeFromString(String stringValue, Integer latestYearRepresentable, Tag tag = ...) Creates a UTCTime from a As the UTCTime class internally contains an Parameters:
|
utf8String | shared UTF8String|EncodingError utf8String(String val, Tag tag = ...) Creates an ASN.1 UTF8String. Restriction from X.690 (07/2002), 8.21.10 is not
(yet) enforced.
(“Announcers and escape sequences shall not be used, and each
character shall be encoded in the smallest number of octets Parameters:
|
Interfaces | |
AnySwitch | shared AnySwitch Manages type information of a SEQUENCE component of type ANY DEFINED BY. |
Classes | |
AnySwitchRegistry | shared abstract AnySwitchRegistry AnySwitch that looks up decoders in a Map, given a discriminator value. |
Asn1Boolean | shared Asn1Boolean Represents an ASN.1 BOOLEAN value. |
Asn1BooleanDecoder | shared Asn1BooleanDecoder Decodes BOOLEAN. Returns an error if the length octets encode any value other than 1 |
Asn1Integer | shared Asn1Integer Represents an ASN.1 INTEGER value, restricted to values representable in 4 octets. For a larger range, please use |
Asn1IntegerDecoder | shared Asn1IntegerDecoder Decodes INTEGER to an |
Asn1Null | shared Asn1Null Represents an ASN.1 NULL value. |
Asn1NullDecoder | shared Asn1NullDecoder Decodes NULL. |
Asn1Sequence | shared Asn1Sequence<out Types> Represents an ASN.1 SEQUENCE value. The |
Asn1SequenceOf | shared Asn1SequenceOf<Inner> Represents an ASN.1 SEQUENCE OF value. |
Asn1Set | shared Asn1Set<Types> Represents an ASN.1 SET value. This is not yet supported, and a Decoder for SET is missing. The |
Asn1SetOf | shared Asn1SetOf<Inner> Represents an ASN.1 SET OF value. |
Asn1Value | shared abstract Asn1Value<out Value> Base class for an ASN.1 value whose type definition is known. This class can store a Ceylon value corresponding to the ASN.1 value, but if that's not feasible (as for example in OCTET STRING: contents possibly long but easy to decode), that Ceylon value may be calculated on the fly from the encoding. |
Asn1Whole | shared Asn1Whole Represents an ASN.1 INTEGER value that can represent arbitrary large values
using |
Asn1WholeDecoder | shared Asn1WholeDecoder Decodes INTEGER to an |
BitString | shared BitString Represents an ASN.1 BIT STRING value. Parameter types of the Asn1Value super class are for octet string contents and number of bits. The last octet in the octet string contents may contain unused bits. |
BitStringDecoder | shared BitStringDecoder Decodes BIT STRING. |
ChoiceDecoder | shared ChoiceDecoder<P> Decodes CHOICE. Type parameter |
Decoder | shared abstract Decoder<out Asn1Type> A decoder for an ASN.1 type. |
DecodingError | shared DecodingError Returned if an error occured while decoding. |
Descriptor | shared Descriptor<out Element> Describes the definition of a SEQUENCE or SET component. Needed because not all information is available in the decoders used. |
EncodingError | shared EncodingError Returned if an error occured while encoding. |
EncodingMethod | shared EncodingMethod Enum class for the length encoding methods. |
GeneralizedTime | shared GeneralizedTime Represents an ASN.1 GeneralizedTime value. |
GeneralizedTimeDecoder | shared GeneralizedTimeDecoder Decodes GeneralizedTime. |
GenericAsn1Value | shared GenericAsn1Value A generic ASN.1 value with the information that can minimally be known without knowledge of its type's ASN.1 definition. A GenericAsn1Value always stores the encoded form. |
GenericAsn1ValueDecoder | shared GenericAsn1ValueDecoder Decodes an ASN.1 value without knowing its type definition. |
GenericSequenceDecoder | shared GenericSequenceDecoder Decodes a SEQUENCE without knowing the ASN.1 specification for it. |
IA5String | shared IA5String Represent an ASN.1 IA5String value. IA5String is treated like ASCII. |
IA5StringDecoder | shared IA5StringDecoder Decodes IA5String. Returns an error if the contents contains octets that are not ASCII values, that is, if they larger than 127. |
IdentityInfo | shared IdentityInfo Information from the identity octets of an ASN.1 value according to the BER. |
ObjectIdentifier | shared ObjectIdentifier Represents an ASN.1 OBJECT IDENTIFIER value. |
ObjectIdentifierDecoder | shared ObjectIdentifierDecoder Decodes OBJECT IDENTIFIER. |
OctetString | shared OctetString Represents an ASN.1 OCTET STRING value. |
OctetStringDecoder | shared OctetStringDecoder Decodes OCTET STRING. |
Option | shared Option Enum class to indicate if a sequence/set value is mandatory or optional. |
PrintableString | shared PrintableString Represents an ASN.1 PrintableString value. |
PrintableStringDecoder | shared PrintableStringDecoder Decodes PrintableString. |
SequenceDecoder | shared SequenceDecoder<out Types> Decodes SEQUENCE. |
SequenceOfDecoder | shared SequenceOfDecoder<Inner> Decodes SEQUENCE OF. |
SetOfDecoder | shared SetOfDecoder<Inner> Decodes a SET OF. |
StdDecoder | shared abstract StdDecoder<Asn1Type> An experimental helper decoder that does calculation and return of the next position value. It is questionable if that is really of much use. |
Tag | shared Tag An ASN.1 tag consisting of tag class and number. |
TagClass | shared TagClass The class of an ASN.1 tag. |
TaggedValue | shared TaggedValue<out Type> Represents an ASN.1 value with an EXPLICIT tag (used in a SEQUENCE, SET or CHOICE). |
TaggedValueDecoder | shared TaggedValueDecoder<Type> Decodes an ASN.1 value with an EXPLICIT tag. |
UTCTime | shared UTCTime Represents an ASN.1 UTCTime value. |
UTCTimeDecoder | shared UTCTimeDecoder Decodes UTCTime. |
UTF8String | shared UTF8String Represents an ASN.1 UTF8String value. |
UTF8StringDecoder | shared UTF8StringDecoder Decodes UTF8String. Returns an error if the contents contains octets that are not a valid UTF-8 sequence. |
UniversalTag | shared UniversalTag Enum class for the (supported) tags in tag class UNIVERSAL. |