Skip to content
This repository has been archived by the owner on Apr 27, 2023. It is now read-only.

Commit

Permalink
Add methods needed for Non Credential Schema Builder (#18)
Browse files Browse the repository at this point in the history
Signed-off-by: Mikaela <[email protected]>
  • Loading branch information
Mikaela Tarkocheva authored Nov 5, 2020
1 parent d25174a commit 1be50fe
Show file tree
Hide file tree
Showing 3 changed files with 104 additions and 0 deletions.
37 changes: 37 additions & 0 deletions pkg/libursa/ursa/ursa.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,43 @@ func CredentialPublicKeyFromJSON(jsn string) (unsafe.Pointer, error) {
return handle, nil
}

//NonCredentialSchemaBuilderNew creates and returns non credential schema builder
func NonCredentialSchemaBuilderNew() (unsafe.Pointer, error) {
var nonBuilder unsafe.Pointer

result := C.ursa_cl_non_credential_schema_builder_new(&nonBuilder)
if result.code != 0 {
return nil, ursaError(C.GoString(result.message))
}

return nonBuilder, nil
}

//NonCredentialSchemaBuilderAddAttr adds new attribute to non credential schema
func NonCredentialSchemaBuilderAddAttr(nonBuilder unsafe.Pointer, attr string) error {
cAttr := C.CString(attr)
defer C.free(unsafe.Pointer(cAttr))

result := C.ursa_cl_non_credential_schema_builder_add_attr(nonBuilder, cAttr)
if result.code != 0 {
return ursaError(C.GoString(result.message))
}

return nil
}

//NonCredentialSchemaBuilderFinalize deallocates non_credential schema builder and returns non credential schema entity instead
func NonCredentialSchemaBuilderFinalize(nonBuilder unsafe.Pointer) (unsafe.Pointer, error) {
var nonSchema unsafe.Pointer

result := C.ursa_cl_non_credential_schema_builder_finalize(nonBuilder, &nonSchema)
if result.code != 0 {
return nil, ursaError(C.GoString(result.message))
}

return nonSchema, nil
}

//CredentialSchemaBuilderNew creates and return credential schema entity builder
func CredentialSchemaBuilderNew() (unsafe.Pointer, error) {
var builder unsafe.Pointer
Expand Down
37 changes: 37 additions & 0 deletions pkg/libursa/ursa/ursa_cl.h
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,43 @@ struct ExternError ursa_cl_signature_correctness_proof_to_json(const void *signa
*/
struct ExternError ursa_cl_credential_signature_free(const void *credential_signature);

/**
* Adds new attribute to non credential schema.
*
* # Arguments
* * `non_credential_schema_builder` - Reference that contains non credential schema builder instance pointer.
* * `attr` - Attribute to add as null terminated string.
*/
struct ExternError ursa_cl_non_credential_schema_builder_add_attr(const void *non_credential_schema_builder,
const char *attr);

/**
* Deallocates non_credential schema builder and returns non credential schema entity instead.
*
* Note: Non credential schema instance deallocation must be performed by
* calling ursa_cl_non_credential_schema_free.
*
* # Arguments
* * `non_credential_schema_builder` - Reference that contains non credential schema builder instance pointer
* * `non_credential_schema_p` - Reference that will contain non credentials schema instance pointer.
*/
struct ExternError ursa_cl_non_credential_schema_builder_finalize(const void *non_credential_schema_builder,
const void **non_credential_schema_p);

/**
* Creates and returns non credential schema builder.
*
* The purpose of non credential schema builder is building of non credential schema that
* represents non credential schema attributes set. These are attributes added to schemas that are not on the ledger
*
* Note: Non credential schema builder instance deallocation must be performed by
* calling ursa_cl_non_credential_schema_builder_finalize.
*
* # Arguments
* * `credential_schema_builder_p` - Reference that will contain credentials attributes builder instance pointer.
*/
struct ExternError ursa_cl_non_credential_schema_builder_new(const void **non_credential_schema_builder_p);

/**
* Creates and returns credential schema entity builder.
*
Expand Down
30 changes: 30 additions & 0 deletions pkg/libursa/ursa/ursa_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,36 @@ func TestCorrectnessProofToJSON(t *testing.T) {
assert.Empty(t, proof)
}

func TestNonCredentialSchemaBuilderNew(t *testing.T) {
t.Run("NonCredentialSchemaBuilderNew", func(t *testing.T) {
nonBuilder, err := NonCredentialSchemaBuilderNew()
assert.Empty(t, err)
assert.NotEmpty(t, nonBuilder)
})
}

func TestNonCredentialSchemaBuilderAddAttr(t *testing.T) {
t.Run("NonCredentialSchemaBuilderAddAttr", func(t *testing.T) {
nonBuilder, _ := NonCredentialSchemaBuilderNew()
originalNonBuilder := nonBuilder

err := NonCredentialSchemaBuilderAddAttr(nonBuilder,"master_secret")
assert.Empty(t, err)
assert.NotSame(t, originalNonBuilder, nonBuilder, "builders should differ after adding attribute")
})
}

func TestNonCredentialSchemaBuilderFinalize(t *testing.T) {
t.Run("NonCredentialSchemaBuilderFinalize", func(t *testing.T) {
nonBuilder, _ := NonCredentialSchemaBuilderNew()
_ = NonCredentialSchemaBuilderAddAttr(nonBuilder,"master_secret")

nonSchema, err := NonCredentialSchemaBuilderFinalize(nonBuilder)
assert.Empty(t, err)
assert.NotEmpty(t, nonSchema)
})
}

func TestCredentialSchemaBuilderNew(t *testing.T) {
t.Run("CredentialSchemaBuilderNew", func(t *testing.T) {
schemaBuilder, err := CredentialSchemaBuilderNew()
Expand Down

0 comments on commit 1be50fe

Please sign in to comment.