mirror of
https://github.com/gregtwallace/apc-p15-tool.git
synced 2025-10-09 22:05:39 +00:00
app: restructure and start building p15 output
This commit is contained in:
parent
6610c92058
commit
e2e4f2037c
24 changed files with 622 additions and 168 deletions
pkg/tools/asn1obj
27
pkg/tools/asn1obj/bitstring.go
Normal file
27
pkg/tools/asn1obj/bitstring.go
Normal file
|
@ -0,0 +1,27 @@
|
|||
package asn1obj
|
||||
|
||||
import (
|
||||
"encoding/asn1"
|
||||
"math/bits"
|
||||
)
|
||||
|
||||
// BitString returns a BIT STRING of the content
|
||||
func BitString(content []byte) []byte {
|
||||
bs := asn1.BitString{
|
||||
Bytes: content,
|
||||
}
|
||||
|
||||
// drop trailing 0s by removing them from overall length
|
||||
if len(content) > 0 {
|
||||
trailing0s := bits.TrailingZeros8(content[len(content)-1])
|
||||
bs.BitLength = 8*len(content) - trailing0s
|
||||
}
|
||||
|
||||
// should never error
|
||||
asn1result, err := asn1.Marshal(bs)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
return asn1result
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue