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

Commit

Permalink
Final wrapped method needed to round trip Indy credentials. (#29)
Browse files Browse the repository at this point in the history
Signed-off-by: Phil Feairheller <[email protected]>
  • Loading branch information
pfeairheller authored Dec 21, 2020
1 parent ef25d0d commit 0eedc27
Show file tree
Hide file tree
Showing 8 changed files with 116 additions and 27 deletions.
5 changes: 4 additions & 1 deletion pkg/libursa/ursa/master_secret.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (

type MasterSecret Handle

// NewMasterSecret creates a master secret
func NewMasterSecret() (*MasterSecret, error) {
var ms unsafe.Pointer

Expand All @@ -23,7 +24,7 @@ func NewMasterSecret() (*MasterSecret, error) {
return &MasterSecret{ms}, nil
}

//MasterSecretFromJson creates and returns nonce json
//MasterSecretFromJson creates and returns master secret from json
func MasterSecretFromJSON(jsn []byte) (*MasterSecret, error) {
var handle unsafe.Pointer
cjson := C.CString(string(jsn))
Expand All @@ -37,6 +38,7 @@ func MasterSecretFromJSON(jsn []byte) (*MasterSecret, error) {
return &MasterSecret{handle}, nil
}

// ToJSON returns json representation of master secret
func (r *MasterSecret) ToJSON() ([]byte, error) {
var d *C.char
defer C.free(unsafe.Pointer(d))
Expand All @@ -50,6 +52,7 @@ func (r *MasterSecret) ToJSON() ([]byte, error) {
return out, nil
}

// Free deallocates master secret instance
func (r *MasterSecret) Free() error {
result := C.ursa_cl_master_secret_free(r.ptr)
if result.code != 0 {
Expand Down
12 changes: 12 additions & 0 deletions pkg/libursa/ursa/proof_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
type ProofBuilder Handle
type ProofHandle Handle

// NewProofBuilder
func NewProofBuilder() (*ProofBuilder, error) {
var builder unsafe.Pointer

Expand All @@ -24,6 +25,7 @@ func NewProofBuilder() (*ProofBuilder, error) {
return &ProofBuilder{builder}, nil
}

// ProofFromJSON creates and returns proof from JSON
func ProofFromJSON(jsn []byte) (*ProofHandle, error) {
var builder unsafe.Pointer
cjson := C.CString(string(jsn))
Expand All @@ -37,6 +39,7 @@ func ProofFromJSON(jsn []byte) (*ProofHandle, error) {
return &ProofHandle{builder}, nil
}

// AddCommonAttribute add a common attribute to the proof builder
func (r *ProofBuilder) AddCommonAttribute(attr string) error {
cattr := C.CString(attr)
defer C.free(unsafe.Pointer(cattr))
Expand All @@ -49,6 +52,7 @@ func (r *ProofBuilder) AddCommonAttribute(attr string) error {
return nil
}

// AddSubProofRequest add a sub proof request to the proof builder
func (r *ProofBuilder) AddSubProofRequest(subProof *SubProofRequestHandle, credSchema *CredentialSchemaHandle,
nonCredSchema *NonCredentialSchemaHandle, signature *CredentialSignature, values *CredentialValues, pubKey *CredentialDefPubKey) error {

Expand All @@ -61,6 +65,7 @@ func (r *ProofBuilder) AddSubProofRequest(subProof *SubProofRequestHandle, credS
return nil
}

// Finalize finalize the proof
func (r *ProofBuilder) Finalize(nonce *Nonce) (*ProofHandle, error) {
var proof unsafe.Pointer

Expand All @@ -72,6 +77,7 @@ func (r *ProofBuilder) Finalize(nonce *Nonce) (*ProofHandle, error) {
return &ProofHandle{proof}, nil
}

// ToJSON returns JSON representation of proof
func (r *ProofHandle) ToJSON() ([]byte, error) {
var d *C.char
defer C.free(unsafe.Pointer(d))
Expand All @@ -84,6 +90,7 @@ func (r *ProofHandle) ToJSON() ([]byte, error) {
return []byte(C.GoString(d)), nil
}

// Free deallocates proof instance
func (r *ProofHandle) Free() error {
result := C.ursa_cl_proof_free(r.ptr)
if result.code != 0 {
Expand All @@ -96,6 +103,7 @@ func (r *ProofHandle) Free() error {
type SubProofRequestBuilder Handle
type SubProofRequestHandle Handle

// NewSubProofRequestBuilder creates and returns sub proof request entity builder
func NewSubProofRequestBuilder() (*SubProofRequestBuilder, error) {
var builder unsafe.Pointer

Expand All @@ -108,6 +116,7 @@ func NewSubProofRequestBuilder() (*SubProofRequestBuilder, error) {

}

// AddPredicate adds predicate to sub proof request
func (r *SubProofRequestBuilder) AddPredicate(attr, ptype string, value int32) error {
cattr := C.CString(attr)
defer C.free(unsafe.Pointer(cattr))
Expand All @@ -122,6 +131,7 @@ func (r *SubProofRequestBuilder) AddPredicate(attr, ptype string, value int32) e
return nil
}

// AddRevealedAttr adds new revealed attribute to sub proof request.
func (r *SubProofRequestBuilder) AddRevealedAttr(attr string) error {
cattr := C.CString(attr)
defer C.free(unsafe.Pointer(cattr))
Expand All @@ -134,6 +144,7 @@ func (r *SubProofRequestBuilder) AddRevealedAttr(attr string) error {
return nil
}

// Finalize deallocates sub proof request builder and returns sub proof request entity instead.
func (r *SubProofRequestBuilder) Finalize() (*SubProofRequestHandle, error) {
var proof unsafe.Pointer

Expand All @@ -145,6 +156,7 @@ func (r *SubProofRequestBuilder) Finalize() (*SubProofRequestHandle, error) {
return &SubProofRequestHandle{proof}, nil
}

// Free deallocates sub proof request instance
func (r *SubProofRequestHandle) Free() error {
result := C.ursa_cl_sub_proof_request_free(r.ptr)
if result.code != 0 {
Expand Down
Loading

0 comments on commit 0eedc27

Please sign in to comment.