From efc55d9237deccf97c9fbdf323de2b39fb4cf0ae Mon Sep 17 00:00:00 2001 From: Stepan Bujnak Date: Fri, 3 Sep 2021 12:32:46 +0200 Subject: [PATCH] Validate Load() and Dump() opertions (#12) --- client_test.go | 3 --- fingerprint.go | 26 ++++++++++++++++++++++---- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/client_test.go b/client_test.go index d4c0f89..9528093 100644 --- a/client_test.go +++ b/client_test.go @@ -21,9 +21,6 @@ func TestClientWithValidCredentials(t *testing.T) { if client.LicenseSearch == nil { t.Fatal("improperly initialized client, missing LicenseSearch") } - if client.AssetLibrary == nil { - t.Fatal("improperly initialized client, missing AssetLibrary") - } } func TestClientWithInvalidCredentials(t *testing.T) { diff --git a/fingerprint.go b/fingerprint.go index fbbc375..cd68e33 100644 --- a/fingerprint.go +++ b/fingerprint.go @@ -31,6 +31,12 @@ func NewFingerprintFromBuffer(buffer []byte) (*Fingerprint, error) { // LoadDumpedfingerprint loads a fingerprint previously serialized by // the Fingerprint.Dump() function. func LoadDumpedFingerprint(dump []byte) (*Fingerprint, error) { + status := C.AE_Status_New() + if status == nil { + panic("out of memory") + } + + defer C.AE_Status_Delete(&status) ft := C.AE_Fingerprint_New() if ft == nil { panic("out of memory") @@ -46,8 +52,11 @@ func LoadDumpedFingerprint(dump []byte) (*Fingerprint, error) { defer C.free(cDump) C.AE_Buffer_Set(b, cDump, C.size_t(len(dump))) - C.AE_Fingerprint_Load(ft, b) + C.AE_Fingerprint_Load(ft, b, status) + if err := statusToError(status); err != nil { + return nil, err + } return &Fingerprint{ft}, nil } @@ -99,17 +108,26 @@ func (f *Fingerprint) Close() error { // Dump serializes the fingerprint into a byte slice so that it can be // stored on a disk or in a dabase. It can later be deserialized with // the LoadDumpedFingerprint() function. -func (f *Fingerprint) Dump() []byte { +func (f *Fingerprint) Dump() ([]byte, error) { + status := C.AE_Status_New() + if status == nil { + panic("out of memory") + } + + defer C.AE_Status_Delete(&status) b := C.AE_Buffer_New() if b == nil { panic("out of memory") } defer C.AE_Buffer_Delete(&b) - C.AE_Fingerprint_Dump(f.ft, b) + C.AE_Fingerprint_Dump(f.ft, b, status) + if err := statusToError(status); err != nil { + return nil, err + } data := C.AE_Buffer_GetData(b) size := C.int(C.AE_Buffer_GetSize(b)) - return C.GoBytes(data, size) + return C.GoBytes(data, size), nil }