2019-06-13 16:09:05 +01:00
|
|
|
// Copyright (C) 2019 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
// #include "uplink_definitions.h"
|
|
|
|
import "C"
|
|
|
|
|
|
|
|
import (
|
|
|
|
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 {
|
2019-06-13 16:09:05 +01:00
|
|
|
apikey, err := libuplink.ParseAPIKey(C.GoString(val))
|
|
|
|
if err != nil {
|
|
|
|
*cerr = C.CString(err.Error())
|
2019-06-15 12:23:12 +01:00
|
|
|
return C.APIKeyRef{}
|
2019-06-13 16:09:05 +01:00
|
|
|
}
|
|
|
|
|
2019-06-15 12:23:12 +01:00
|
|
|
return C.APIKeyRef{universe.Add(apikey)}
|
2019-06-13 16:09:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//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 {
|
2019-06-13 16:09:05 +01:00
|
|
|
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
|
2019-06-13 16:09:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
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) {
|
2019-06-13 16:09:05 +01:00
|
|
|
universe.Del(apikeyHandle._handle)
|
|
|
|
}
|