storj/lib/uplinkc/apikey.go

44 lines
979 B
Go
Raw Normal View History

// Copyright (C) 2019 Storj Labs, Inc.
// See LICENSE for copying information.
package main
// #include "uplink_definitions.h"
import "C"
import (
"fmt"
libuplink "storj.io/storj/lib/uplink"
)
//export parse_api_key
// parse_api_key parses an API Key
2019-06-15 12:23:12 +01:00
func parse_api_key(val *C.char, cerr **C.char) C.APIKeyRef {
apikey, err := libuplink.ParseAPIKey(C.GoString(val))
if err != nil {
*cerr = C.CString(fmt.Sprintf("%+v", err))
2019-06-15 12:23:12 +01:00
return C.APIKeyRef{}
}
2019-06-15 12:23:12 +01:00
return C.APIKeyRef{universe.Add(apikey)}
}
//export serialize_api_key
// serialize_api_key serializes the API Key to a string
2019-06-15 12:23:12 +01:00
func serialize_api_key(apikeyHandle C.APIKeyRef, cerr **C.char) *C.char {
apikey, ok := universe.Get(apikeyHandle._handle).(libuplink.APIKey)
if !ok {
2019-06-15 12:23:12 +01:00
*cerr = C.CString("invalid apikey")
return nil
}
return C.CString(apikey.Serialize())
}
//export free_api_key
// free_api_key frees an api key
2019-06-15 12:23:12 +01:00
func free_api_key(apikeyHandle C.APIKeyRef) {
universe.Del(apikeyHandle._handle)
}