Sign in

    moonbitstack/mooncrypt/asn1 does not have a README file

    Refused

    pub(all) suberror Refused {
    Malformed(String)
    Unsupported(String)
    } derive(Eq)

    A refused encoding. Malformed is a hostile or corrupt certificate; Unsupported is well-formed DER this parser deliberately does not read, and the two are separated so a caller can log an interop gap without calling it an attack.
    impl Show for Refused

    Refused::equal

    fn Refused::equal(Refused, Refused) -> Bool

    Refused::not_equal

    fn Refused::not_equal(x : Refused, y : Refused) -> Bool

    Refused::output

    fn Refused::output(self : Refused, logger : &Logger) -> Unit

    Refused::to_string

    fn Refused::to_string(self : Refused) -> String

    Bits

    pub(all) struct Bits {
    bytes : Bytes
    unused : Int
    } derive(Eq,
    Debug
    )

    A decoded BIT STRING: the content bytes and how many low bits of the last byte are padding.

    Bits::equal

    fn Bits::equal(Bits, Bits) -> Bool

    Bits::get

    fn Bits::get(self : Bits, i : Int) -> Bool

    Whether bit i is set, counting from the most significant bit of the first byte — the numbering X.509 uses for keyUsage. Bits inside the padding, or past the end, read as unset.

    Bits::not_equal

    fn Bits::not_equal(x : Bits, y : Bits) -> Bool

    Bits::to_repr

    Tlv

    pub(all) struct Tlv {
    tag : Int
    value : BytesView
    raw : BytesView
    }

    One decoded element: the tag byte, the contents, and raw — tag, length and contents together. raw is what a signature covers and how far to step to reach the next element.

    Tlv::bits

    fn Tlv::bits(self : Tlv) -> Bits raise Refused

    A BIT STRING.

    Tlv::bool

    fn Tlv::bool(self : Tlv) -> Bool raise Refused

    A BOOLEAN. DER admits only 0x00 and 0xFF, so any other octet is refused.

    Tlv::int

    An INTEGER, two's complement as X.690 §8.3 defines it.

    Tlv::items

    fn Tlv::items(self : Tlv) -> Array[Tlv] raise Refused

    The elements a constructed value holds, in encoding order.

    Tlv::octets

    fn Tlv::octets(self : Tlv) -> BytesView raise Refused

    An OCTET STRING's contents.

    Tlv::oid

    fn Tlv::oid(self : Tlv) -> String raise Refused

    An OBJECT IDENTIFIER in dotted-decimal form. The first octet packs two arcs (X.690 §8.19.4); the rest are base-128, high bit set on every byte but an arc's last.

    Tlv::text

    fn Tlv::text(self : Tlv) -> String raise Refused

    A DirectoryString or IA5String as text — the string types an X.509 Name and a SAN entry are written in. UniversalString is refused: it is UTF-32 and no certificate in practice uses it.

    Tlv::time

    fn Tlv::time(self : Tlv) -> Int64 raise Refused

    A UTCTime or GeneralizedTime as seconds since the Unix epoch. RFC 5280 §4.1.2.5 pins both to the seconds-and-Z form, and a two-digit year to 1950..2049, so the other shapes X.690 allows are refused rather than guessed at.

    ascii

    fn ascii(v : BytesView) -> String raise Refused

    Octets of one of the ASCII string types as text. Taken on its own because a subjectAltName tags its entries with the field number, not the string type, so the octets arrive with nothing left to dispatch on.

    bit_string

    fn bit_string(content : Bytes) -> Bytes

    A DER BIT STRING (tag 0x03) with no unused trailing bits: a leading 0x00 count then content.

    context

    fn context(tag : Int, n : Int) -> Bool

    Whether tag is the context-specific [n] of an IMPLICIT or EXPLICIT field.

    explicit

    fn explicit(tag_num : Int, content : Bytes) -> Bytes

    A context-specific constructed value [tag_num] wrapping content (tag 0xA0 | tag_num) — the EXPLICIT tagging X.509 uses for the certificate version and extensions.

    integer

    fn integer(magnitude : Bytes) -> Bytes

    A DER INTEGER (tag 0x02) from a big-endian magnitude: strip redundant leading zero bytes, then prepend one 0x00 if the top bit is set, so the value stays non-negative (X.690 §8.3).

    length_of

    fn length_of(n : Int) -> Bytes

    Encode a definite length (X.690 §8.1.3): the short form is the single byte for lengths under 128; the long form is 0x80 | n followed by the length in n big-endian bytes.

    null

    fn null() -> Bytes

    A DER NULL (tag 0x05, empty).

    octet_string

    fn octet_string(content : Bytes) -> Bytes

    A DER OCTET STRING (tag 0x04).

    oid

    fn oid(arcs : Array[Int]) -> Bytes

    A DER OBJECT IDENTIFIER (tag 0x06) from its arcs (X.690 §8.19): the first byte encodes 40·arc1 + arc2, and each later arc is base-128 big-endian with the high bit set on every byte but the last.

    only

    fn only(input : BytesView) -> Tlv raise Refused

    Read the one element that is the whole of input. Bytes after it are an error — a certificate with a payload glued to its end is two documents, and the second one is not covered by the signature over the first.

    read

    fn read(input : BytesView) -> Tlv raise Refused

    Read the element at the head of input. Raises rather than reading past the end: the length is checked against the bytes that remain, in 64-bit arithmetic so a length near 2^31 cannot wrap the check.

    sequence

    fn sequence(elements : Array[Bytes]) -> Bytes

    A DER SEQUENCE (tag 0x30): the concatenated elements.

    set_of

    fn set_of(elements : Array[Bytes]) -> Bytes

    A DER SET (tag 0x31): the concatenated elements.

    tlv

    fn tlv(tag : Int, value : Bytes) -> Bytes

    A tag-length-value: the tag byte, the definite length of value, then value.

    utc_time

    fn utc_time(s : String) -> Bytes

    A DER UTCTime (tag 0x17), the YYMMDDHHMMSSZ form X.509 validity uses before 2050.

    utf8_string

    fn utf8_string(s : String) -> Bytes

    A DER UTF8String (tag 0x0c).

    Source Files