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
73823549
Commit
73823549
authored
Sep 18, 2017
by
Sietse Ringers
Browse files
Add Manager.CredentialList()
parent
58b74cb1
Changes
2
Hide whitespace changes
Inline
Side-by-side
credential.go
View file @
73823549
package
irmago
import
"github.com/mhe/gabi"
import
(
"strings"
"github.com/mhe/gabi"
)
// credential represents an IRMA credential, whose zeroth attribute
// is always the secret key and the first attribute the metadata attribute.
type
credential
struct
{
*
gabi
.
Credential
*
MetadataAttribute
info
*
Credential
}
// A Credential contains all information of an IRMA credential.
type
Credential
struct
{
ID
string
// e.g., "irma-demo.RU.studentCard"
SignedOn
Timestamp
// Unix timestamp
Expires
Timestamp
// Unix timestamp
Type
*
CredentialType
// Credential information from MetaStore
Issuer
*
Issuer
// Issuer information from MetaStore
SchemeManager
*
SchemeManager
// Scheme manager information from MetaStore
Attributes
[]
TranslatedString
// Human-readable rendered attributes
Logo
string
// Path to logo on storage
}
// A CredentialList is a list of credentials (implements sort.Interface).
type
CredentialList
[]
*
Credential
func
newCredential
(
gabicred
*
gabi
.
Credential
)
(
cred
*
credential
)
{
cred
=
&
credential
{}
cred
.
Credential
=
gabicred
cred
.
MetadataAttribute
=
MetadataFromInt
(
gabicred
.
Attributes
[
1
])
cred
.
Pk
=
MetaStore
.
PublicKey
(
cred
.
CredentialType
()
.
IssuerIdentifier
(),
cred
.
KeyCounter
())
meta
:=
MetadataFromInt
(
gabicred
.
Attributes
[
1
])
credtype
:=
meta
.
CredentialType
()
issid
:=
credtype
.
IssuerIdentifier
()
attrs
:=
make
([]
TranslatedString
,
len
(
credtype
.
Attributes
))
for
i
:=
range
credtype
.
Attributes
{
val
:=
string
(
gabicred
.
Attributes
[
i
+
2
]
.
Bytes
())
attrs
[
i
]
=
TranslatedString
(
map
[
string
]
string
{
"en"
:
val
,
"nl"
:
val
})
}
cred
=
&
credential
{
Credential
:
gabicred
,
MetadataAttribute
:
meta
,
info
:
&
Credential
{
ID
:
credtype
.
Identifier
()
.
String
(),
SignedOn
:
Timestamp
(
meta
.
SigningDate
()),
Expires
:
Timestamp
(
meta
.
Expiry
()),
Type
:
credtype
,
Issuer
:
MetaStore
.
Issuers
[
issid
],
SchemeManager
:
MetaStore
.
SchemeManagers
[
issid
.
SchemeManagerIdentifier
()],
Attributes
:
attrs
,
Logo
:
""
,
// TODO
},
}
cred
.
Pk
=
MetaStore
.
PublicKey
(
issid
,
cred
.
KeyCounter
())
return
}
// Len implements sort.Interface.
func
(
cl
CredentialList
)
Len
()
int
{
return
len
(
cl
)
}
// Swap implements sort.Interface.
func
(
cl
CredentialList
)
Swap
(
i
,
j
int
)
{
cl
[
i
],
cl
[
j
]
=
cl
[
j
],
cl
[
i
]
}
// Less implements sort.Interface.
func
(
cl
CredentialList
)
Less
(
i
,
j
int
)
bool
{
// TODO Decide on sorting, and if it depends on a TranslatedString, allow language choosing
return
strings
.
Compare
(
cl
[
i
]
.
Type
.
Name
[
"en"
],
cl
[
j
]
.
Type
.
Name
[
"en"
])
>
0
}
manager.go
View file @
73823549
...
...
@@ -6,6 +6,8 @@ import (
"crypto/rand"
"sort"
"github.com/Roasbeef/go-go-gadget-paillier"
"github.com/mhe/gabi"
)
...
...
@@ -31,6 +33,17 @@ func newCredentialManager() *CredentialManager {
}
}
func
(
cm
*
CredentialManager
)
CredentialList
()
CredentialList
{
list
:=
CredentialList
([]
*
Credential
{})
for
_
,
credlist
:=
range
cm
.
credentials
{
for
_
,
cred
:=
range
credlist
{
list
=
append
(
list
,
cred
.
info
)
}
}
sort
.
Sort
(
list
)
return
list
}
func
(
cm
*
CredentialManager
)
generateSecretKey
()
(
sk
*
big
.
Int
,
err
error
)
{
return
gabi
.
RandomBigInt
(
gabi
.
DefaultSystemParameters
[
1024
]
.
Lm
)
}
...
...
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