Commit 78d71579 authored by Sietse Ringers's avatar Sietse Ringers
Browse files

Group credential removal log entries

parent 8925f452
......@@ -15,9 +15,9 @@ type LogEntry struct {
SessionInfo *SessionInfo // Message that started the session
// Session type-specific info
RemovedCredential CredentialTypeIdentifier // In case of credential removal
Disclosed map[CredentialTypeIdentifier]map[int]TranslatedString // Any session type
Received map[CredentialTypeIdentifier][]TranslatedString // In case of issuance session
Removed map[CredentialTypeIdentifier][]TranslatedString // In case of credential removal
SignedMessage []byte // In case of signature sessions
SignedMessageType string // In case of signature sessions
......@@ -122,9 +122,9 @@ type jsonLogEntry struct {
Time Timestamp
SessionInfo *logSessionInfo
RemovedCredential string `json:",omitempty"`
Disclosed map[CredentialTypeIdentifier]map[int]TranslatedString `json:",omitempty"`
Received map[CredentialTypeIdentifier][]TranslatedString `json:",omitempty"`
Removed map[CredentialTypeIdentifier][]TranslatedString `json:",omitempty"`
SignedMessage []byte `json:",omitempty"`
SignedMessageType string `json:",omitempty"`
......@@ -147,7 +147,7 @@ func (entry *LogEntry) UnmarshalJSON(bytes []byte) error {
Context: temp.SessionInfo.Context,
Keys: make(map[IssuerIdentifier]int),
},
RemovedCredential: NewCredentialTypeIdentifier(temp.RemovedCredential),
Removed: temp.Removed,
Disclosed: temp.Disclosed,
Received: temp.Received,
SignedMessage: temp.SignedMessage,
......@@ -191,7 +191,7 @@ func (entry *LogEntry) MarshalJSON() ([]byte, error) {
Time: entry.Time,
Response: entry.rawResponse,
SessionInfo: si,
RemovedCredential: entry.RemovedCredential.String(),
Removed: entry.Removed,
Disclosed: entry.Disclosed,
Received: entry.Received,
SignedMessage: entry.SignedMessage,
......
......@@ -227,11 +227,17 @@ func (cm *CredentialManager) remove(id CredentialTypeIdentifier, index int, stor
return err
}
removed := map[CredentialTypeIdentifier][]TranslatedString{}
removed[id] = attrs.Strings()
if storenow {
return cm.addLogEntry(&LogEntry{
Type: actionRemoval,
Time: Timestamp(time.Now()),
RemovedCredential: id,
}, storenow)
Removed: removed,
})
}
return nil
}
func (cm *CredentialManager) RemoveCredential(id CredentialTypeIdentifier, index int) error {
......@@ -247,19 +253,31 @@ func (cm *CredentialManager) RemoveCredentialByHash(hash string) error {
}
func (cm *CredentialManager) RemoveAllCredentials() error {
removed := map[CredentialTypeIdentifier][]TranslatedString{}
list := cm.CredentialInfoList()
for _, cred := range list {
if err := cm.remove(NewCredentialTypeIdentifier(cred.ID), cred.Index, false); err != nil {
id := NewCredentialTypeIdentifier(cred.ID)
removed[id] = cred.Attributes
if err := cm.remove(id, cred.Index, false); err != nil {
return err
}
}
if err := cm.storage.StoreAttributes(cm.attributes); err != nil {
return err
}
logentry := &LogEntry{
Type: actionRemoval,
Time: Timestamp(time.Now()),
Removed: removed,
}
if err := cm.addLogEntry(logentry); err != nil {
return err
}
return cm.storage.StoreLogs(cm.logs)
}
// Getter methods
// Attribute and credential getter methods
// attrs returns cm.attributes[id], initializing it to an empty slice if neccesary
func (cm *CredentialManager) attrs(id CredentialTypeIdentifier) []*AttributeList {
......@@ -607,11 +625,9 @@ func (cm *CredentialManager) KeyshareRemove(manager SchemeManagerIdentifier) err
// Add, load and store log entries
func (cm *CredentialManager) addLogEntry(entry *LogEntry, storenow bool) error {
func (cm *CredentialManager) addLogEntry(entry *LogEntry) error {
cm.logs = append(cm.logs, entry)
if storenow {
return cm.storage.StoreLogs(cm.logs)
}
return nil
}
......
......@@ -289,6 +289,6 @@ func (session *session) sendResponse(message interface{}) {
log, _ = session.createLogEntry(message) // TODO err
}
_ = session.credManager.addLogEntry(log, true) // TODO err
_ = session.credManager.addLogEntry(log) // TODO err
session.Handler.Success(session.Action)
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment