Ejemplo n.º 1
0
// ParseCert creates certificate context from byte slice
func ParseCert(buf []byte) (res Cert, err error) {
	bufBytes := C.CBytes(buf)
	defer C.free(bufBytes)

	res.pCert = C.CertCreateCertificateContext(C.MY_ENC_TYPE, (*C.BYTE)(bufBytes), C.DWORD(len(buf)))
	if res.pCert == nil {
		err = getErr("Error creating certficate context")
		return
	}
	return
}
Ejemplo n.º 2
0
// NewCert creates certificate context from io.Reader containing certificate
// in X509 encoding
func NewCert(r io.Reader) (*Cert, error) {
	var pCert C.PCCERT_CONTEXT
	buf, err := ioutil.ReadAll(r)
	if err != nil {
		return nil, err
	}
	pCert = C.CertCreateCertificateContext(C.MY_ENC_TYPE, (*C.BYTE)(unsafe.Pointer(&buf[0])), C.DWORD(len(buf)))
	if pCert == C.PCCERT_CONTEXT(nil) {
		return nil, getErr("Error creating certficate context")
	}
	return &Cert{pCert}, nil
}