Skip to content

Commit

Permalink
Merge pull request #32 from hannesm/fix-regression
Browse files Browse the repository at this point in the history
Fix regression for 0x05 0x80
  • Loading branch information
hannesm committed Jan 28, 2020
2 parents 13fe41f + 17d733e commit 5978e4e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/asn_ber_der.ml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ module R = struct
let rec f cs i = function
0 -> 0L
| n -> match get_uint8 cs i with
0 when cfg.strict -> error cs "redudnant length"
0 when cfg.strict -> error cs "redundant length"
| 0 -> f cs (i + 1) (n - 1)
| _ when n > 8 -> error cs "length overflow"
| x -> g (Int64.of_int x) cs (i + 1) (n - 1)
Expand Down Expand Up @@ -103,7 +103,13 @@ module R = struct
| 0x80 -> Tag.Context_specific tag_v
| _ -> Tag.Private tag_v
and coding =
(* according to layman's guide to a subset of ASN.1, BER, and DER, there
are three possibilities in BER (DER restricts this further):
- (a) primitive + definitive length
- (b) constructed + definitive length
- (c) constructed + indefinite length *)
match (t0 land 0x20, l0) with
| (0, 0x80) -> error cs "primitive and indefinite length"
| (0, _ ) -> Primitive len
| (_, 0x80) -> Constructed_indefinite
| _ -> Constructed len in
Expand Down
3 changes: 3 additions & 0 deletions tests/test.ml
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,9 @@ let anticases = [
case "silly bit strings" Asn.S.bit_string
[ "0300"; "030101"; "030208ff" ];
case "null with indefinite length" Asn.S.null
[ "0580"; "058000"; "05800000" ]
]
let der_anticases = [
Expand Down

0 comments on commit 5978e4e

Please sign in to comment.