diff --git a/cshared/main.go b/cshared/main.go index 927719f..fb0e024 100644 --- a/cshared/main.go +++ b/cshared/main.go @@ -149,4 +149,29 @@ func SignForPython(configFilePath *C.char, digest *byte, digestLen int, sigHolde return len(signature) } +// GetKeyType returns a string representing ECP's key type. +// The key is derived from the ECP configuration. +// +//export GetKeyType +func GetKeyType(configFilePath *C.char) *C.char { + key, err := client.Cred(C.GoString(configFilePath)) + if err != nil { + log.Printf("Could not create client using config %s: %v", C.GoString(configFilePath), err) + return C.CString("unknown") + } + defer func() { + if err = key.Close(); err != nil { + log.Printf("Failed to clean up key. %v", err) + } + }() + switch key.Public().(type) { + case *ecdsa.PublicKey: + return C.CString("EC") + case *rsa.PublicKey: + return C.CString("RSA") + default: + return C.CString("unknown") + } +} + func main() {}