Update Go API to version 1.2

Add Certificate Object, support parse, check and access (very limited)
attributes of an X.509 certificate in PEM format.
This commit is contained in:
Zhi Guan
2018-07-15 10:54:52 +08:00
parent a0e5d103ba
commit 27940499bc
7 changed files with 169 additions and 45 deletions

View File

@@ -8,9 +8,8 @@ import "C"
import (
"errors"
"fmt"
"runtime"
"unsafe"
"runtime"
)
/* generated by `gmssl list -cipher-algorithms | sort -f | uniq -i` */
@@ -171,7 +170,7 @@ func GetCipherKeyLength(name string) (int, error) {
defer C.free(unsafe.Pointer(cname))
cipher := C.EVP_get_cipherbyname(cname)
if cipher == nil {
return 0, errors.New("Invalid cipher name")
return 0, GetErrors()
}
return int(C.EVP_CIPHER_key_length(cipher)), nil
}
@@ -181,7 +180,7 @@ func GetCipherBlockLength(name string) (int, error) {
defer C.free(unsafe.Pointer(cname))
cipher := C.EVP_get_cipherbyname(cname)
if cipher == nil {
return 0, errors.New("Invalid cipher")
return 0, GetErrors()
}
return int(C.EVP_CIPHER_block_size(cipher)), nil
}
@@ -191,7 +190,7 @@ func GetCipherIVLength(name string) (int, error) {
defer C.free(unsafe.Pointer(cname))
cipher := C.EVP_get_cipherbyname(cname)
if cipher == nil {
return 0, errors.New("Invalid cipher")
return 0, GetErrors()
}
return int(C.EVP_CIPHER_iv_length(cipher)), nil
}
@@ -208,7 +207,7 @@ func NewCipherContext(name string, eng *Engine, key, iv []byte, encrypt bool) (
cipher := C.EVP_get_cipherbyname(cname)
if cipher == nil {
return nil, fmt.Errorf("shit")
return nil, GetErrors()
}
if key == nil {
@@ -229,7 +228,7 @@ func NewCipherContext(name string, eng *Engine, key, iv []byte, encrypt bool) (
ctx := C.EVP_CIPHER_CTX_new()
if ctx == nil {
return nil, fmt.Errorf("shit")
return nil, GetErrors()
}
ret := &CipherContext{ctx}
@@ -244,7 +243,7 @@ func NewCipherContext(name string, eng *Engine, key, iv []byte, encrypt bool) (
if 1 != C.EVP_CipherInit(ctx, cipher, (*C.uchar)(&key[0]),
(*C.uchar)(&iv[0]), C.int(enc)) {
return nil, fmt.Errorf("shit")
return nil, GetErrors()
}
return ret, nil
@@ -255,7 +254,7 @@ func (ctx *CipherContext) Update(in []byte) ([]byte, error) {
outlen := C.int(len(outbuf))
if 1 != C.EVP_CipherUpdate(ctx.ctx, (*C.uchar)(&outbuf[0]), &outlen,
(*C.uchar)(&in[0]), C.int(len(in))) {
return nil, fmt.Errorf("failed to decrypt")
return nil, GetErrors()
}
return outbuf[:outlen], nil
}
@@ -264,7 +263,7 @@ func (ctx *CipherContext) Final() ([]byte, error) {
outbuf := make([]byte, int(C.EVP_CIPHER_CTX_block_size(ctx.ctx)))
outlen := C.int(len(outbuf))
if 1 != C.EVP_CipherFinal(ctx.ctx, (*C.uchar)(&outbuf[0]), &outlen) {
return nil, fmt.Errorf("failed to decrypt")
return nil, GetErrors()
}
return outbuf[:outlen], nil
}