Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
IRMA
Github mirrors
irmago
Commits
972085b9
Commit
972085b9
authored
Jul 24, 2017
by
Sietse Ringers
Browse files
Add convenience methods
parent
1f6763ab
Changes
1
Hide whitespace changes
Inline
Side-by-side
manager.go
View file @
972085b9
...
...
@@ -49,10 +49,30 @@ func (cm *CredentialManager) Init(path string) (err error) {
}
// attrs returns cm.attributes[id], initializing it to an empty slice if neccesary
func
(
cm
*
CredentialManager
)
attrs
(
id
string
)
[]
*
AttributeList
{
list
,
exists
:=
cm
.
attributes
[
id
]
if
!
exists
{
list
=
make
([]
*
AttributeList
,
0
,
1
)
cm
.
attributes
[
id
]
=
list
}
return
list
}
// creds returns cm.credentials[id], initializing it to an empty map if neccesary
func
(
cm
*
CredentialManager
)
creds
(
id
string
)
map
[
int
]
*
gabi
.
Credential
{
list
,
exists
:=
cm
.
credentials
[
id
]
if
!
exists
{
list
=
make
(
map
[
int
]
*
gabi
.
Credential
)
cm
.
credentials
[
id
]
=
list
}
return
list
}
// Attributes returns the attribute list of the requested credential, or nil if we do not have it.
func
(
cm
*
CredentialManager
)
Attributes
(
id
string
,
counter
int
)
(
attributes
*
AttributeList
)
{
list
,
exists
:=
cm
.
attr
ibutes
[
id
]
if
!
exists
||
len
(
list
)
<=
counter
{
list
:=
cm
.
attr
s
(
id
)
if
len
(
list
)
<=
counter
{
return
}
return
list
[
counter
]
...
...
@@ -60,15 +80,10 @@ func (cm *CredentialManager) Attributes(id string, counter int) (attributes *Att
// Credential returns the requested credential, or nil if we do not have it.
func
(
cm
*
CredentialManager
)
Credential
(
id
string
,
counter
int
)
(
cred
*
gabi
.
Credential
,
err
error
)
{
_
,
exists
:=
cm
.
credentials
[
id
]
if
!
exists
{
cm
.
credentials
[
id
]
=
make
(
map
[
int
]
*
gabi
.
Credential
)
}
// If the requested credential is not in credential map, we check if its attributes were
// deserialized during Init(). If so, there should be a corresponding signature file,
// so we read that, construct the credential, and add it to the credential map
if
_
,
exists
:=
cm
.
cred
entials
[
id
]
[
counter
];
!
exists
{
if
_
,
exists
:=
cm
.
cred
s
(
id
)
[
counter
];
!
exists
{
attrs
:=
cm
.
Attributes
(
id
,
counter
)
if
attrs
==
nil
{
// We do not have the requested cred
return
...
...
@@ -151,10 +166,7 @@ func (cm *CredentialManager) ParseAndroidStorage() (err error) {
func
(
cm
*
CredentialManager
)
addCredential
(
cred
*
gabi
.
Credential
)
{
id
:=
cred
.
CredentialType
()
.
Identifier
()
if
_
,
exists
:=
cm
.
attributes
[
id
];
!
exists
{
cm
.
attributes
[
id
]
=
make
([]
*
AttributeList
,
0
,
1
)
}
cm
.
attributes
[
id
]
=
append
(
cm
.
attributes
[
id
],
NewAttributeListFromInts
(
cred
.
Attributes
[
1
:
]))
cm
.
attributes
[
id
]
=
append
(
cm
.
attrs
(
id
),
NewAttributeListFromInts
(
cred
.
Attributes
[
1
:
]))
if
_
,
exists
:=
cm
.
credentials
[
id
];
!
exists
{
cm
.
credentials
[
id
]
=
make
(
map
[
int
]
*
gabi
.
Credential
)
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment