module

Beryl::Encoding::DistinguishedEncodingRules

Reads DER, the Distinguished Encoding Rules of ITU-T X.690 §10, the encoding of certificates, keys and signatures.

Only the one canonical encoding of each value is accepted: definite lengths in their shortest form, tags in their shortest form, minimal integers, BOOLEAN as 0x00 or 0xFF, BIT STRING padding bits set to zero, and the two time forms RFC 5280 §4.1.2.5 allows. Every read checks the bytes left before it touches them, and nesting deeper than Limits#largest_nesting_depth is refused, so a hostile input can raise MalformedEncoding or LimitExceeded and nothing else.

reader = Beryl::Encoding::DER::Reader.new(certificate_bytes)
reader.read_sequence do |certificate|
  to_be_signed = certificate.read_element(DER::SEQUENCE)
  # ...
end
reader.finish

Constants

BIT_STRING = Tag.universal(3)
BMP_STRING = Tag.universal(30)
BOOLEAN = Tag.universal(1)
GENERALIZED_TIME = Tag.universal(24)
IA5_STRING = Tag.universal(22)
INTEGER = Tag.universal(2)
NULL = Tag.universal(5)
OBJECT_IDENTIFIER = Tag.universal(6)
OCTET_STRING = Tag.universal(4)
PRINTABLE_STRING = Tag.universal(19)
SEQUENCE = Tag.universal(16, is_constructed: true)
SET = Tag.universal(17, is_constructed: true)
TELETEX_STRING = Tag.universal(20)
UNIVERSAL_STRING = Tag.universal(28)
UTC_TIME = Tag.universal(23)
UTF8_STRING = Tag.universal(12)

Nested types