Source File
asn1.go
Belonging Package
vendor/golang.org/x/crypto/cryptobyte
package cryptobyte
import (
encoding_asn1
)
func ( *Builder) ( int64) {
.addASN1Signed(asn1.INTEGER, )
}
func ( *Builder) ( int64, asn1.Tag) {
.addASN1Signed(, )
}
func ( *Builder) ( []byte) {
.AddASN1(asn1.OCTET_STRING, func( *Builder) {
.AddBytes()
})
}
const generalizedTimeFormatStr = "20060102150405Z0700"
func ( *Builder) ( []byte) {
.AddASN1(asn1.BIT_STRING, func( *Builder) {
.AddUint8(0)
.AddBytes()
})
}
func ( *Builder) ( int64) {
var int
if == 0 {
= 1
} else {
for := ; > 0; >>= 7 {
++
}
}
for := - 1; >= 0; -- {
:= byte( >> uint(*7))
&= 0x7f
if != 0 {
|= 0x80
}
.add()
}
}
func ( encoding_asn1.ObjectIdentifier) bool {
if len() < 2 {
return false
}
if [0] > 2 || ([0] <= 1 && [1] >= 40) {
return false
}
for , := range {
if < 0 {
return false
}
}
return true
}
func ( *Builder) ( encoding_asn1.ObjectIdentifier) {
.AddASN1(asn1.OBJECT_IDENTIFIER, func( *Builder) {
if !isValidOID() {
.err = fmt.Errorf("cryptobyte: invalid OID: %v", )
return
}
.addBase128Int(int64([0])*40 + int64([1]))
for , := range [2:] {
.addBase128Int(int64())
}
})
}
func ( *Builder) ( bool) {
.AddASN1(asn1.BOOLEAN, func( *Builder) {
if {
.AddUint8(0xff)
} else {
.AddUint8(0)
}
})
}
func ( *Builder) () {
.add(uint8(asn1.NULL), 0)
}
func ( *String) ( interface{}) bool {
if reflect.TypeOf().Kind() != reflect.Ptr {
panic("out is not a pointer")
}
switch reflect.ValueOf().Elem().Kind() {
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
var int64
if !.readASN1Int64(&) || reflect.ValueOf().Elem().OverflowInt() {
return false
}
reflect.ValueOf().Elem().SetInt()
return true
case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
var uint64
if !.readASN1Uint64(&) || reflect.ValueOf().Elem().OverflowUint() {
return false
}
reflect.ValueOf().Elem().SetUint()
return true
case reflect.Struct:
if reflect.TypeOf().Elem() == bigIntType {
return .readASN1BigInt(.(*big.Int))
}
}
panic("out does not point to an integer type")
}
func ( []byte) bool {
:= make([]byte, len())
for , := range {
[] = ^
}
.SetBytes()
.Add(, bigOne)
.Neg()
} else {
.SetBytes()
}
return true
}
func ( *String) ( *int64) bool {
var String
if !.ReadASN1(&, asn1.INTEGER) || !checkASN1Integer() || !asn1Signed(, ) {
return false
}
return true
}
func ( *int64, []byte) bool {
:= len()
if > 8 {
return false
}
for := 0; < ; ++ {
* <<= 8
* |= int64([])
return false
}
func ( *String) ( *int64, asn1.Tag) bool {
var String
return .ReadASN1(&, ) && checkASN1Integer() && asn1Signed(, )
}
func ( *String) ( *int) bool {
var String
var int64
if !.ReadASN1(&, asn1.ENUM) || !checkASN1Integer() || !asn1Signed(&, ) {
return false
}
if int64(int()) != {
return false
}
* = int()
return true
}
func ( *String) ( *int) bool {
:= 0
for := 0; len(*) > 0; ++ {
if == 4 {
return false
}
<<= 7
:= .read(1)[0]
|= int( & 0x7f)
if &0x80 == 0 {
* =
return true
}
}
return false // truncated
}
func ( *String) ( *encoding_asn1.ObjectIdentifier) bool {
var String
if !.ReadASN1(&, asn1.OBJECT_IDENTIFIER) || len() == 0 {
return false
}
var int
if !.readBase128Int(&) {
return false
}
if < 80 {
[0] = / 40
[1] = % 40
} else {
[0] = 2
[1] = - 80
}
:= 2
for ; len() > 0; ++ {
if !.readBase128Int(&) {
return false
}
[] =
}
* = [:]
return true
}
func ( *String) ( *encoding_asn1.BitString) bool {
var String
if !.ReadASN1(&, asn1.BIT_STRING) || len() == 0 ||
len()*8/8 != len() {
return false
}
:= uint8([0])
= [1:]
if > 7 ||
len() == 0 && != 0 ||
len() > 0 && [len()-1]&(1<<-1) != 0 {
return false
}
.BitLength = len()*8 - int()
.Bytes =
return true
}
func ( *String) ( interface{}, asn1.Tag, interface{}) bool {
if reflect.TypeOf().Kind() != reflect.Ptr {
panic("out is not a pointer")
}
var bool
var String
if !.ReadOptionalASN1(&, &, ) {
return false
}
if ! {
switch reflect.ValueOf().Elem().Kind() {
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64,
reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
reflect.ValueOf().Elem().Set(reflect.ValueOf())
case reflect.Struct:
if reflect.TypeOf().Elem() != bigIntType {
panic("invalid integer type")
}
if reflect.TypeOf().Kind() != reflect.Ptr ||
reflect.TypeOf().Elem() != bigIntType {
panic("out points to big.Int, but defaultValue does not")
}
.(*big.Int).Set(.(*big.Int))
default:
panic("invalid integer type")
}
return true
}
if !.ReadASN1Integer() || !.Empty() {
return false
}
return true
}
var , uint32 // length includes headerLen
= uint32() + 2
= 2
return false
}
![]() |
The pages are generated with Golds v0.3.2-preview. (GOOS=darwin GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds. |