length.bend checks
raw source on the hub · import 0xeb25eff332574f4f1d48668b83cdda30/length.bend as Length
bend-osdev-asn1, length octets (ITU-T X.690 (02/2021) 8.1.3): the definite short form (one octet, bit 8 zero, 8.1.3.4), the definite long form (an initial octet 80 hex + k, k from 1 to 126, then k octets of the length, big-endian, 8.1.3.5; FF is not used), and the indefinite form (80 hex, 8.1.3.6). The encoder writes the definite form in the fewest octets, as DER requires (10.1).
4 imports
import Base import bend-osdev-bytes@0.1.0.0/bytes.bend as B import ./error.bend as E import ./number.bend as Nu
Types
type A1Len source · line 14 · raw
Data
Length octets, read: a definite length (with the octets it took), the indefinite form, or an error
A1LDef@len:Nat -> @used:List<&2, U32> -> @rest:List<&2, U32> -> A1Len
A1LIndef@rest:List<&2, U32> -> A1Len
A1LErr@error:0xeb25eff332574f4f1d48668b83cdda30/error.Asn1Error -> A1Len
Definitions
def a1.len_pick source · line 19 · raw
@lt:Bool -> @+n:Nat -> List<&2, U32>
def a1.len_bytes source · line 28 · raw
@+n:Nat -> List<&2, U32>
the definite length octets of n, as few as possible (8.1.3.3, 10.1)
def a1.len_ok.pick source · line 31 · raw
@lt:Bool -> @+n:Nat -> Bool
def a1.len_ok source · line 40 · raw
@+n:Nat -> Bool
whether n has length octets here: the long form holds at most 126 octets (8.1.3.5), and this implementation reads at most six (number.bend)
def a1.len.bytes source · line 43 · raw
@y:U32 -> @m:Maybe<&2, 0xeb25eff332574f4f1d48668b83cdda30/number.A1Num> -> A1Len
def a1.len.many source · line 50 · raw
@big:Bool -> @+k:Nat -> @y:U32 -> @+t:List<&2, U32> -> A1Len
def a1.len.reserved source · line 57 · raw
@is127:Bool -> @+k:Nat -> @y:U32 -> @+t:List<&2, U32> -> A1Len
def a1.len.long source · line 64 · raw
@+k:Nat -> @y:U32 -> @+t:List<&2, U32> -> A1Len
def a1.len.first source · line 71 · raw
@lt:Bool -> @+v:Nat -> @y:U32 -> @+t:List<&2, U32> -> A1Len
def a1.len.read source · line 79 · raw
@xs:List<&2, U32> -> A1Len
the length octets at the start of xs