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 }
//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 }
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 }
func (bio *BIO) Ctrl(cmd int, larg int, data unsafe.Pointer) int { return int(C.BIO_ctrl(bio.BIO, C.int(cmd), C.long(larg), data)) }