本文整理汇总了Golang中C.BIO_new函数的典型用法代码示例。如果您正苦于以下问题:Golang BIO_new函数的具体用法?Golang BIO_new怎么用?Golang BIO_new使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了BIO_new函数的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Print
func (self *X509Name) Print() ([]byte, error) {
bio := C.BIO_new(C.BIO_s_mem())
defer C.BIO_free(bio)
//TODO check for error here
C.X509_NAME_print_ex(bio, self.Name, 0, C.XN_FLAG_MULTILINE)
var temp *C.char
buf_len := C.BIO_ctrl(bio, C.BIO_CTRL_INFO, 0, unsafe.Pointer(&temp))
return C.GoBytes(unsafe.Pointer(temp), C.int(buf_len)), nil
}
示例2: DumpDERCertificate
//Export an OpenSSL X509 to a DER buffer
func (self *Certificate) DumpDERCertificate() ([]byte, error) {
bio := C.BIO_new(C.BIO_s_mem())
defer C.BIO_free(bio)
ret := C.i2d_X509_bio(bio, self.x509)
if ret == 0 {
return nil, errors.New("problem dumping certificate")
}
var temp *C.char
buf_len := C.BIO_ctrl(bio, C.BIO_CTRL_INFO, 0, unsafe.Pointer(&temp))
return C.GoBytes(unsafe.Pointer(temp), C.int(buf_len)), nil
}
示例3: MarshalPEM
// MarshalPEM converts the X509 certificate to PEM-encoded format
func (c *Certificate) MarshalPEM() (pem_block []byte, err error) {
bio := C.BIO_new(C.BIO_s_mem())
if bio == nil {
return nil, errors.New("failed to allocate memory BIO")
}
defer C.BIO_free(bio)
if int(C.PEM_write_bio_X509(bio, c.x)) != 1 {
return nil, errors.New("failed dumping certificate")
}
return ioutil.ReadAll(asAnyBio(bio))
}
示例4: X509NamePrintEx
func (c *Certificate) X509NamePrintEx() (out []byte, err error) {
bio := C.BIO_new(C.BIO_s_mem())
if bio == nil {
return nil, errors.New("failed to allocate memory BIO")
}
defer C.BIO_free(bio)
name := C.X509_get_subject_name(c.x)
// TODO, pass in flags instead of using this hardcoded one
if int(C.X509_NAME_print_ex(bio, name, 0, C.XN_FLAG_RFC2253)) < 0 {
return nil, errors.New("failed formatting subject")
}
return ioutil.ReadAll(asAnyBio(bio))
}
示例5: DumpPEM
func (self *PKey) DumpPEM() ([]byte, error) {
bio := C.BIO_new(C.BIO_s_mem())
defer C.BIO_free(bio)
if bio == nil {
return nil, errors.New("problem converting pem key to openssl key")
}
ret := C.PEM_write_bio_PrivateKey(bio, self.PKey, nil, nil, 0, nil, nil)
if int(ret) == 0 {
return nil, errors.New(sslerr.SSLErrorMessage())
}
var temp *C.char
buf_len := C.BIO_ctrl(bio, C.BIO_CTRL_INFO, C.long(0), unsafe.Pointer(&temp))
buffer := C.GoBytes(unsafe.Pointer(temp), C.int(buf_len))
return buffer, nil
}
示例6: MarshalPKIXPublicKeyDER
func (key *pKey) MarshalPKIXPublicKeyDER() (der_block []byte,
err error) {
bio := C.BIO_new(C.BIO_s_mem())
if bio == nil {
return nil, errors.New("failed to allocate memory BIO")
}
defer C.BIO_free(bio)
rsa := (*C.RSA)(C.EVP_PKEY_get1_RSA(key.key))
if rsa == nil {
return nil, errors.New("failed getting rsa key")
}
defer C.RSA_free(rsa)
if int(C.i2d_RSA_PUBKEY_bio(bio, rsa)) != 1 {
return nil, errors.New("failed dumping public key der")
}
return ioutil.ReadAll(asAnyBio(bio))
}
示例7: MarshalPKCS1PrivateKeyPEM
func (key *pKey) MarshalPKCS1PrivateKeyPEM() (pem_block []byte,
err error) {
bio := C.BIO_new(C.BIO_s_mem())
if bio == nil {
return nil, errors.New("failed to allocate memory BIO")
}
defer C.BIO_free(bio)
rsa := (*C.RSA)(C.EVP_PKEY_get1_RSA(key.key))
if rsa == nil {
return nil, errors.New("failed getting rsa key")
}
defer C.RSA_free(rsa)
if int(C.PEM_write_bio_RSAPrivateKey(bio, rsa, nil, nil, C.int(0), nil,
nil)) != 1 {
return nil, errors.New("failed dumping private key")
}
return ioutil.ReadAll(asAnyBio(bio))
}
示例8: NewBIO
func NewBIO(method *BIOMethod) *BIO {
return &BIO{BIO: C.BIO_new(method.BIOMethod)}
}
示例9: MakeCBIO
func (b *readBio) MakeCBIO() *C.BIO {
b.buf = bufPool.Get()
rv := C.BIO_new(C.BIO_s_readBio())
rv.ptr = unsafe.Pointer(b)
return rv
}
示例10: MakeCBIO
func (b *readBio) MakeCBIO() *C.BIO {
rv := C.BIO_new(C.BIO_s_readBio())
token := readBioMapping.Add(unsafe.Pointer(b))
rv.ptr = unsafe.Pointer(token)
return rv
}
示例11: NewBIO
func NewBIO(method *BIOMethod) *BIO {
return newBIO(C.BIO_new(method.BIOMethod))
}