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
bc56c0fe
Commit
bc56c0fe
authored
Oct 15, 2017
by
Sietse Ringers
Browse files
Properly handle duplicate and singleton credentials
parent
4a35b5d6
Changes
1
Hide whitespace changes
Inline
Side-by-side
manager.go
View file @
bc56c0fe
...
...
@@ -170,17 +170,28 @@ func (cm *CredentialManager) CredentialInfoList() CredentialInfoList {
// imediately, and optionally cm.attributes as well.
func
(
cm
*
CredentialManager
)
addCredential
(
cred
*
credential
,
storeAttributes
bool
)
(
err
error
)
{
id
:=
cred
.
CredentialType
()
.
Identifier
()
cm
.
attributes
[
id
]
=
append
(
cm
.
attrs
(
id
),
cred
.
AttributeList
())
// Don't add duplicate creds
for
_
,
attrlistlist
:=
range
cm
.
attributes
{
for
_
,
attrs
:=
range
attrlistlist
{
if
attrs
.
hash
()
==
cred
.
AttributeList
()
.
hash
()
{
return
nil
}
}
}
// If this is a singleton credential type, ensure we have at most one by removing any previous instance
if
cred
.
CredentialType
()
.
IsSingleton
&&
len
(
cm
.
creds
(
id
))
>
0
{
cm
.
remove
(
id
,
0
,
false
)
// Index is 0, because if we're here we have exactly one
}
// Append the new cred to our attributes and credentials
cm
.
attributes
[
id
]
=
append
(
cm
.
attrs
(
id
),
cred
.
AttributeList
())
if
_
,
exists
:=
cm
.
credentials
[
id
];
!
exists
{
cm
.
credentials
[
id
]
=
make
(
map
[
int
]
*
credential
)
}
if
cred
.
CredentialType
()
.
IsSingleton
{
cm
.
credentials
[
id
][
0
]
=
cred
}
else
{
counter
:=
len
(
cm
.
attributes
[
id
])
-
1
cm
.
credentials
[
id
][
counter
]
=
cred
}
counter
:=
len
(
cm
.
attributes
[
id
])
-
1
cm
.
credentials
[
id
][
counter
]
=
cred
if
err
=
cm
.
storage
.
StoreSignature
(
cred
);
err
!=
nil
{
return
...
...
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