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
c736be28
Commit
c736be28
authored
Sep 27, 2017
by
Sietse Ringers
Browse files
Improve identifier (de)serialization
parent
e49c7e6a
Changes
3
Hide whitespace changes
Inline
Side-by-side
attributes.go
View file @
c736be28
...
...
@@ -87,16 +87,6 @@ func (al *AttributeList) Info() *Credential {
return
al
.
info
}
// TODO maybe remove
func
(
al
*
AttributeList
)
hash
()
string
{
bytes
:=
make
([]
byte
,
20
)
for
_
,
i
:=
range
al
.
Ints
{
bytes
=
append
(
bytes
,
i
.
Bytes
()
...
)
}
shasum
:=
sha256
.
Sum256
(
bytes
)
return
string
(
shasum
[
:
])
}
// Strings converts the current instance to human-readable strings.
func
(
al
*
AttributeList
)
Strings
()
[]
string
{
if
al
.
strings
==
nil
{
...
...
identifiers.go
View file @
c736be28
package
irmago
import
(
"encoding/json"
"strings"
)
import
"strings"
type
metaObjectIdentifier
string
...
...
@@ -104,40 +101,46 @@ func (ai *AttributeIdentifier) CredentialIdentifier() CredentialIdentifier {
return
CredentialIdentifier
{
Type
:
ai
.
Type
.
CredentialTypeIdentifier
(),
Index
:
ai
.
Index
,
Count
:
ai
.
Count
}
}
// Marshal
JSON marshals this instance to JSON as a string
.
func
(
id
AttributeType
Identifier
)
Marshal
JSON
()
([]
byte
,
error
)
{
return
json
.
Marshal
(
id
.
String
())
// Marshal
Text implements encoding.TextMarshaler
.
func
(
id
SchemeManager
Identifier
)
Marshal
Text
()
([]
byte
,
error
)
{
return
[]
byte
(
id
.
String
())
,
nil
}
// MarshalJSON marshals this instance to JSON as a string.
func
(
id
CredentialTypeIdentifier
)
MarshalJSON
()
([]
byte
,
error
)
{
return
json
.
Marshal
(
id
.
String
())
// UnmarshalText implements encoding.TextUnmarshaler.
func
(
id
*
SchemeManagerIdentifier
)
UnmarshalText
(
text
[]
byte
)
error
{
*
id
=
NewSchemeManagerIdentifier
(
string
(
text
))
return
nil
}
// MarshalText implements encoding.TextMarshaler.
func
(
id
IssuerIdentifier
)
MarshalText
()
([]
byte
,
error
)
{
return
[]
byte
(
id
.
String
()),
nil
}
// UnmarshalJSON unmarshals this instance from JSON.
func
(
id
*
AttributeTypeIdentifier
)
UnmarshalJSON
(
b
[]
byte
)
error
{
var
val
string
err
:=
json
.
Unmarshal
(
b
,
&
val
)
if
err
!=
nil
{
return
err
}
id
.
metaObjectIdentifier
=
metaObjectIdentifier
(
val
)
// UnmarshalText implements encoding.TextUnmarshaler.
func
(
id
*
IssuerIdentifier
)
UnmarshalText
(
text
[]
byte
)
error
{
*
id
=
NewIssuerIdentifier
(
string
(
text
))
return
nil
}
//
Unm
arshal
JSON unmarshals this instance from JSON
.
func
(
id
*
CredentialTypeIdentifier
)
Unm
arshal
JSON
(
b
[]
byte
)
error
{
var
val
string
err
:=
json
.
Unmarshal
(
b
,
&
val
)
if
err
!=
nil
{
return
err
}
id
.
metaObjectIdentifier
=
metaObjectIdentifier
(
val
)
//
M
arshal
Text implements encoding.TextMarshaler
.
func
(
id
CredentialTypeIdentifier
)
M
arshal
Text
()
(
[]
byte
,
error
)
{
return
[]
byte
(
id
.
String
()),
nil
}
// UnmarshalText implements encoding.TextUnmarshaler.
func
(
id
*
CredentialTypeIdentifier
)
UnmarshalText
(
text
[]
byte
)
error
{
*
id
=
NewCredentialTypeIdentifier
(
string
(
text
)
)
return
nil
}
// TODO this also for the other identifiers
func
(
id
*
IssuerIdentifier
)
UnmarshalText
(
text
[]
byte
)
error
{
*
id
=
NewIssuerIdentifier
(
string
(
text
))
// MarshalText implements encoding.TextMarshaler.
func
(
id
AttributeTypeIdentifier
)
MarshalText
()
([]
byte
,
error
)
{
return
[]
byte
(
id
.
String
()),
nil
}
// UnmarshalText implements encoding.TextUnmarshaler.
func
(
id
*
AttributeTypeIdentifier
)
UnmarshalText
(
text
[]
byte
)
error
{
*
id
=
NewAttributeTypeIdentifier
(
string
(
text
))
return
nil
}
storage.go
View file @
c736be28
...
...
@@ -110,7 +110,7 @@ func (cm *CredentialManager) ParseAndroidStorage() (err error) {
xml
.
Unmarshal
(
bytes
,
&
parsedxml
)
parsedjson
:=
make
(
map
[
string
][]
*
gabi
.
Credential
)
parsedksse
s
:
=
make
(
map
[
string
]
*
keyshareServer
)
cm
.
keyshareServer
s
=
make
(
map
[
SchemeManagerIdentifier
]
*
keyshareServer
)
for
_
,
xmltag
:=
range
parsedxml
.
Strings
{
if
xmltag
.
Name
==
"credentials"
{
jsontag
:=
html
.
UnescapeString
(
xmltag
.
Content
)
...
...
@@ -120,7 +120,7 @@ func (cm *CredentialManager) ParseAndroidStorage() (err error) {
}
if
xmltag
.
Name
==
"keyshare"
{
jsontag
:=
html
.
UnescapeString
(
xmltag
.
Content
)
if
err
=
json
.
Unmarshal
([]
byte
(
jsontag
),
&
parsedksse
s
);
err
!=
nil
{
if
err
=
json
.
Unmarshal
([]
byte
(
jsontag
),
&
cm
.
keyshareServer
s
);
err
!=
nil
{
return
}
}
...
...
@@ -134,10 +134,6 @@ func (cm *CredentialManager) ParseAndroidStorage() (err error) {
}
}
for
name
,
kss
:=
range
parsedksses
{
cm
.
keyshareServers
[
NewSchemeManagerIdentifier
(
name
)]
=
kss
}
for
_
,
list
:=
range
parsedjson
{
cm
.
secretkey
=
list
[
0
]
.
Attributes
[
0
]
for
i
,
gabicred
:=
range
list
{
...
...
@@ -261,13 +257,7 @@ func (cm *CredentialManager) storeSignature(cred *credential, counter int) (err
}
func
(
cm
*
CredentialManager
)
storeAttributes
()
(
err
error
)
{
// Unfortunately, the type of cm.attributes (map[CredentialTypeIdentifier][]*AttributeList)
// cannot be passed directly to json.Marshal(), so we copy it into a temp list.
temp
:=
make
(
map
[
string
][]
*
AttributeList
)
for
credid
,
list
:=
range
cm
.
attributes
{
temp
[
credid
.
String
()]
=
list
}
attrbytes
,
err
:=
json
.
Marshal
(
temp
)
attrbytes
,
err
:=
json
.
Marshal
(
cm
.
attributes
)
if
err
!=
nil
{
return
err
}
...
...
@@ -278,11 +268,7 @@ func (cm *CredentialManager) storeAttributes() (err error) {
}
func
(
cm
*
CredentialManager
)
storeKeyshareServers
()
(
err
error
)
{
temp
:=
make
(
map
[
string
]
*
keyshareServer
)
for
name
,
kss
:=
range
cm
.
keyshareServers
{
temp
[
name
.
String
()]
=
kss
}
bts
,
err
:=
json
.
Marshal
(
temp
)
bts
,
err
:=
json
.
Marshal
(
cm
.
keyshareServers
)
if
err
!=
nil
{
return
}
...
...
@@ -345,32 +331,24 @@ func (cm *CredentialManager) loadSecretKey() (*big.Int, error) {
func
(
cm
*
CredentialManager
)
loadAttributes
()
(
list
map
[
CredentialTypeIdentifier
][]
*
AttributeList
,
err
error
)
{
list
=
make
(
map
[
CredentialTypeIdentifier
][]
*
AttributeList
)
temp
:=
make
(
map
[
string
][]
*
AttributeList
)
exists
,
err
:=
PathExists
(
cm
.
path
(
attributesFile
))
if
err
!=
nil
||
!
exists
{
return
}
bytes
,
err
:=
ioutil
.
ReadFile
(
cm
.
path
(
attributesFile
))
if
err
!=
nil
{
return
nil
,
err
}
err
=
json
.
Unmarshal
(
bytes
,
&
temp
)
err
=
json
.
Unmarshal
(
bytes
,
&
list
)
if
err
!=
nil
{
return
nil
,
err
}
for
credid
,
attrs
:=
range
temp
{
list
[
NewCredentialTypeIdentifier
(
credid
)]
=
attrs
}
return
list
,
nil
}
func
(
cm
*
CredentialManager
)
loadKeyshareServers
()
(
ksses
map
[
SchemeManagerIdentifier
]
*
keyshareServer
,
err
error
)
{
ksses
=
make
(
map
[
SchemeManagerIdentifier
]
*
keyshareServer
)
temp
:=
make
(
map
[
string
]
*
keyshareServer
)
exists
,
err
:=
PathExists
(
cm
.
path
(
kssFile
))
if
err
!=
nil
||
!
exists
{
return
...
...
@@ -379,13 +357,10 @@ func (cm *CredentialManager) loadKeyshareServers() (ksses map[SchemeManagerIdent
if
err
!=
nil
{
return
nil
,
err
}
err
=
json
.
Unmarshal
(
bytes
,
&
temp
)
err
=
json
.
Unmarshal
(
bytes
,
&
ksses
)
if
err
!=
nil
{
return
nil
,
err
}
for
name
,
kss
:=
range
temp
{
ksses
[
NewSchemeManagerIdentifier
(
name
)]
=
kss
}
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