MCPcopy Create free account
hub / github.com/egonelbre/exp / AsBitString

Method AsBitString

ber/value.go:164–184  ·  view source on GitHub ↗

BIT STRING AsBitString parses an ASN.1 bit string from the given byte slice and returns it.

()

Source from the content-addressed store, hash-verified

162
163// AsBitString parses an ASN.1 bit string from the given byte slice and returns it.
164func (v *Token) AsBitString() (ret asn1.BitString, err error) {
165 v.mustBeValue()
166 bytes := v.Bytes
167 if len(bytes) == 0 {
168 err = SyntaxError{"zero length BIT STRING"}
169 return
170 }
171 paddingBits := int(bytes[0])
172 if paddingBits > 7 ||
173 len(bytes) == 1 && paddingBits > 0 {
174 err = SyntaxError{"invalid padding bits in BIT STRING"}
175 return
176 }
177 ret.BitLength = (len(bytes)-1)*8 - paddingBits
178 ret.Bytes = bytes[1:]
179
180 // remove the padding bits
181 last := len(ret.Bytes) - 1
182 ret.Bytes[last] = (ret.Bytes[last] >> uint(paddingBits)) << uint(paddingBits)
183 return
184}
185
186func (v *Token) AsOctetString() (ret []byte, err error) {
187 v.mustBeValue()

Callers 1

UniversalMethod · 0.95

Calls 1

mustBeValueMethod · 0.95

Tested by

no test coverage detected