From 5192b8e9cff794f454726945ed9aa0a1ada7b778 Mon Sep 17 00:00:00 2001 From: Carl Lundin <108372512+clundin25@users.noreply.github.com> Date: Mon, 16 Oct 2023 15:14:29 -0700 Subject: [PATCH] feat: Add KeyType API. (#105) * feat: Add KeyType API. --- cshared/main.go | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) 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() {}