Skip to content

Commit

Permalink
Validate Load() and Dump() opertions (#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
stepanbujnak authored Sep 3, 2021
1 parent a189044 commit efc55d9
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
3 changes: 0 additions & 3 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
26 changes: 22 additions & 4 deletions fingerprint.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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
}

Expand Down Expand Up @@ -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
}

0 comments on commit efc55d9

Please sign in to comment.