Debian Codegraph @

cert/asn1.go

raw
1 package cert
2
3 import (
4 "golang.org/x/crypto/cryptobyte"
5 "golang.org/x/crypto/cryptobyte/asn1"
6 )
7
8 // readOptionalASN1Boolean reads an asn.1 boolean with a specific tag instead of a asn.1 tag wrapping a boolean with a value
9 // https://github.com/golang/go/issues/64811#issuecomment-1944446920
10 func readOptionalASN1Boolean(b *cryptobyte.String, out *bool, tag asn1.Tag, defaultValue bool) bool {
11 var present bool
12 var child cryptobyte.String
13 if !b.ReadOptionalASN1(&child, &present, tag) {
14 return false
15 }
16
17 if !present {
18 *out = defaultValue
19 return true
20 }
21
22 // Ensure we have 1 byte
23 if len(child) == 1 {
24 *out = child[0] > 0
25 return true
26 }
27
28 return false
29 }
30
31 // readOptionalASN1Byte reads an asn.1 uint8 with a specific tag instead of a asn.1 tag wrapping a uint8 with a value
32 // Similar issue as with readOptionalASN1Boolean
33 func readOptionalASN1Byte(b *cryptobyte.String, out *byte, tag asn1.Tag, defaultValue byte) bool {
34 var present bool
35 var child cryptobyte.String
36 if !b.ReadOptionalASN1(&child, &present, tag) {
37 return false
38 }
39
40 if !present {
41 *out = defaultValue
42 return true
43 }
44
45 // Ensure we have 1 byte
46 if len(child) == 1 {
47 *out = child[0]
48 return true
49 }
50
51 return false
52 }