Exemple #1
0
// SetSerial sets the serial of a certificate.
func (c *Certificate) SetSerial(serial *big.Int) error {
	sno := C.ASN1_INTEGER_new()
	defer C.ASN1_INTEGER_free(sno)
	bn := C.BN_new()
	defer C.BN_free(bn)

	serialBytes := serial.Bytes()
	if bn = C.BN_bin2bn((*C.uchar)(unsafe.Pointer(&serialBytes[0])), C.int(len(serialBytes)), bn); bn == nil {
		return errors.New("failed to set serial")
	}
	if sno = C.BN_to_ASN1_INTEGER(bn, sno); sno == nil {
		return errors.New("failed to set serial")
	}
	if C.X509_set_serialNumber(c.x, sno) != 1 {
		return errors.New("failed to set serial")
	}
	return nil
}
Exemple #2
0
func (n *bignum) SetBytes(buf []byte) *bignum {
	if C.BN_bin2bn((*_Ctype_unsignedchar)(unsafe.Pointer(&buf[0])), C.int(len(buf)), n.bn) != n.bn {
		panic("BN_bin2bn failed: " + getErrString())
	}
	return n
}