mirror of
https://github.com/guanzhi/GmSSL.git
synced 2026-08-09 23:43:41 +08:00
update go api
This commit is contained in:
@@ -7,7 +7,10 @@ package gmssl
|
||||
import "C"
|
||||
|
||||
import (
|
||||
"runtime"
|
||||
"errors"
|
||||
"unsafe"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
func GetEngineNames() []string {
|
||||
@@ -19,19 +22,63 @@ type Engine struct {
|
||||
}
|
||||
|
||||
func OpenEngine(name string, args map[string]string) (*Engine, error) {
|
||||
return nil, errors.New("Not implemented")
|
||||
cname := C.CString(name)
|
||||
defer C.free(unsafe.Pointer(cname))
|
||||
|
||||
engine := C.ENGINE_by_id(cname)
|
||||
if engine == nil {
|
||||
return nil, fmt.Errorf("shit")
|
||||
}
|
||||
|
||||
ret := &Engine{engine}
|
||||
runtime.SetFinalizer(ret, func(ret *Engine) {
|
||||
C.ENGINE_free(ret.engine)
|
||||
})
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
func (eng *Engine) ExecuteCommand(cmd_name string, arg string, optinal bool) (string, error) {
|
||||
return "", errors.New("Not implemented")
|
||||
func (eng *Engine) ExecuteCommand(cmd_name string, arg string, optinal bool) error {
|
||||
ccmd := C.CString(cmd_name)
|
||||
defer C.free(unsafe.Pointer(ccmd))
|
||||
carg := C.CString(arg)
|
||||
defer C.free(unsafe.Pointer(carg))
|
||||
|
||||
if 1 != C.ENGINE_ctrl_cmd_string(eng.engine, ccmd, carg, 0) {
|
||||
return errors.New("Not implemented")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (eng *Engine) LoadPrivateKey(key_id string, args map[string]string) (*PrivateKey, error) {
|
||||
return nil, errors.New("Not implemented")
|
||||
cid := C.CString(key_id)
|
||||
defer C.free(unsafe.Pointer(cid))
|
||||
|
||||
pkey := C.ENGINE_load_private_key(eng.engine, cid, C.NULL, C.NULL)
|
||||
if pkey == nil {
|
||||
return nil, fmt.Errorf("shit")
|
||||
}
|
||||
|
||||
ret := &PrivateKey{pkey}
|
||||
runtime.SetFinalizer(ret, func(ret *PrivateKey) {
|
||||
C.EVP_PKEY_free(ret.pkey)
|
||||
})
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
func (eng *Engine) LoadPublicKey(key_id string, args map[string]string) (*PublicKey, error) {
|
||||
return nil, errors.New("Not implemented")
|
||||
cid := C.CString(key_id)
|
||||
defer C.free(unsafe.Pointer(cid))
|
||||
|
||||
pkey := C.ENGINE_load_public_key(eng.engine, cid, C.NULL, C.NULL)
|
||||
if pkey == nil {
|
||||
return nil, fmt.Errorf("shit")
|
||||
}
|
||||
|
||||
ret := &PublicKey{pkey}
|
||||
runtime.SetFinalizer(ret, func(ret *PublicKey) {
|
||||
C.EVP_PKEY_free(ret.pkey)
|
||||
})
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
func (eng *Engine) LoadCertificate(ca_dn []string, args map[string]string) (string, error) {
|
||||
|
||||
Reference in New Issue
Block a user