Skip to content

Commit

Permalink
added backward compatability code
Browse files Browse the repository at this point in the history
  • Loading branch information
mishasizov-SK committed Feb 26, 2024
1 parent 98d0248 commit e0d9ae1
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 1 deletion.
17 changes: 17 additions & 0 deletions cmd/wallet-sdk-gomobile/openid4ci/credentialconfigurations.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,30 @@ import (
// SupportedCredentials represents the credentials (types and formats) that an issuer can issue.
type SupportedCredentials struct {
credentialConfigurations map[issuer.CredentialConfigurationID]*issuer.CredentialConfigurationSupported
// credentialConfigurationsList added for backward compatability with iOS and Android integration test code.
// Deprecated.
// Use credentialConfigurations instead.
credentialConfigurationsList []*issuer.CredentialConfigurationSupported
}

// Length returns the number of SupportedCredentials contained within this object.
func (s *SupportedCredentials) Length() int {
return len(s.credentialConfigurations)
}

// AtIndex returns the SupportedCredential at the given index.
// If the index passed in is out of bounds, then nil is returned.
// Deprecated.
// Use CredentialConfigurationSupported instead.
func (s *SupportedCredentials) AtIndex(index int) *SupportedCredential {
maxIndex := len(s.credentialConfigurationsList) - 1
if index > maxIndex || index < 0 {
return nil
}

return &SupportedCredential{credentialConfigurationSupported: s.credentialConfigurationsList[index]}
}

// CredentialConfigurationSupported returns the SupportedCredential by given credentialConfigurationID.
// If credentialConfigurationID is unknown, then nil is returned.
func (s *SupportedCredentials) CredentialConfigurationSupported(
Expand Down
11 changes: 10 additions & 1 deletion cmd/wallet-sdk-gomobile/openid4ci/issuermetadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,16 @@ func (i *IssuerMetadata) CredentialIssuer() string {
// SupportedCredentials returns an object that can be used to determine the types of
// credentials that the issuer supports issuance of.
func (i *IssuerMetadata) SupportedCredentials() *SupportedCredentials {
return &SupportedCredentials{credentialConfigurations: i.issuerMetadata.CredentialConfigurationsSupported}
supportedCredentials := &SupportedCredentials{
credentialConfigurations: i.issuerMetadata.CredentialConfigurationsSupported,
}

for _, credentialConf := range i.issuerMetadata.CredentialConfigurationsSupported {
supportedCredentials.credentialConfigurationsList = append(
supportedCredentials.credentialConfigurationsList, credentialConf)
}

return supportedCredentials
}

// LocalizedIssuerDisplays returns an object that contains display information for the issuer in various locales.
Expand Down
1 change: 1 addition & 0 deletions cmd/wallet-sdk-gomobile/openid4ci/issuermetadata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ func TestIssuerMetadata(t *testing.T) {
credentialConfigurationsSupported := issuerMetadata.SupportedCredentials()
require.NotNil(t, credentialConfigurationsSupported)
require.Equal(t, 1, credentialConfigurationsSupported.Length())
require.NotNil(t, credentialConfigurationsSupported.AtIndex(0))

credentialConfigurationSupported := credentialConfigurationsSupported.
CredentialConfigurationSupported("PermanentResidentCard_jwt_vc_json-ld_v1")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ func TestWalletInitiatedInteraction_Flow(t *testing.T) {

supportedCredentials := issuerMetadata.SupportedCredentials()
require.Equal(t, 1, supportedCredentials.Length())
require.NotNil(t, supportedCredentials.AtIndex(0))

prc := supportedCredentials.CredentialConfigurationSupported("PermanentResidentCard_jwt_vc_json-ld_v1")

Expand Down

0 comments on commit e0d9ae1

Please sign in to comment.