Created
November 19, 2014 01:44
-
-
Save lunixbochs/49fc48fad6e02bac7703 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/cert.go b/cert.go | |
index 0d4a1be..8dc82f8 100644 | |
--- a/cert.go | |
+++ b/cert.go | |
@@ -90,7 +90,7 @@ func (n *Name) AddTextEntry(field, value string) error { | |
defer C.free(unsafe.Pointer(cvalue)) | |
ret := C.X509_NAME_add_entry_by_txt( | |
n.name, cfield, C.MBSTRING_ASC, cvalue, -1, -1, 0) | |
- if ret == 0 { | |
+ if ret != 1 { | |
return errors.New("failed to add x509 name text entry") | |
} | |
return nil | |
@@ -162,7 +162,7 @@ func (c *Certificate) GetIssuerName() (*Name, error) { | |
} | |
func (c *Certificate) SetSubjectName(name *Name) error { | |
- if C.X509_set_subject_name(c.x, name.name) == 0 { | |
+ if C.X509_set_subject_name(c.x, name.name) != 1 { | |
return errors.New("failed to set subject name") | |
} | |
return nil | |
@@ -186,7 +186,7 @@ func (c *Certificate) SetIssuer(issuer *Certificate) error { | |
// SetIssuerName populates the issuer name of a certificate. | |
// Use SetIssuer instead, if possible. | |
func (c *Certificate) SetIssuerName(name *Name) error { | |
- if C.X509_set_issuer_name(c.x, name.name) == 0 { | |
+ if C.X509_set_issuer_name(c.x, name.name) != 1 { | |
return errors.New("failed to set subject name") | |
} | |
return nil | |
@@ -194,7 +194,7 @@ func (c *Certificate) SetIssuerName(name *Name) error { | |
// SetSerial sets the serial of a certificate. | |
func (c *Certificate) SetSerial(serial int) error { | |
- if C.ASN1_INTEGER_set(C.X509_get_serialNumber(c.x), C.long(serial)) == 0 { | |
+ if C.ASN1_INTEGER_set(C.X509_get_serialNumber(c.x), C.long(serial)) != 1 { | |
return errors.New("failed to set serial") | |
} | |
return nil | |
@@ -223,7 +223,7 @@ func (c *Certificate) SetExpireDate(when time.Duration) error { | |
// SetPubKey assigns a new public key to a certificate. | |
func (c *Certificate) SetPubKey(pubKey PublicKey) error { | |
c.pubKey = pubKey | |
- if C.X509_set_pubkey(c.x, pubKey.evpPKey()) == 0 { | |
+ if C.X509_set_pubkey(c.x, pubKey.evpPKey()) != 1 { | |
return errors.New("failed to set public key") | |
} | |
return nil | |
@@ -271,7 +271,7 @@ func (c *Certificate) insecureSign(privKey PrivateKey, digest EVP_MD) error { | |
case EVP_SHA512: | |
md = C.EVP_sha512() | |
} | |
- if C.X509_sign(c.x, privKey.evpPKey(), md) == 0 { | |
+ if C.X509_sign(c.x, privKey.evpPKey(), md) <= 0 { | |
return errors.New("failed to sign certificate") | |
} | |
return nil | |
@@ -291,7 +291,7 @@ func (c *Certificate) AddExtension(nid NID, value string) error { | |
return errors.New("failed to create x509v3 extension") | |
} | |
defer C.X509_EXTENSION_free(ex) | |
- if C.X509_add_ext(c.x, ex, -1) == 0 { | |
+ if C.X509_add_ext(c.x, ex, -1) <= 0 { | |
return errors.New("failed to add x509v3 extension") | |
} | |
return nil | |
diff --git a/key.go b/key.go | |
index 2f8fc7e..2c4eceb 100644 | |
--- a/key.go | |
+++ b/key.go | |
@@ -321,7 +321,7 @@ func GenerateRSAKey(bits int) (PrivateKey, error) { | |
if key == nil { | |
return nil, errors.New("failed to allocate EVP_PKEY") | |
} | |
- if C.EVP_PKEY_assign(key, C.EVP_PKEY_RSA, unsafe.Pointer(rsa)) == 0 { | |
+ if C.EVP_PKEY_assign(key, C.EVP_PKEY_RSA, unsafe.Pointer(rsa)) != 1 { | |
C.EVP_PKEY_free(key) | |
return nil, errors.New("failed to assign RSA key") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment