Commit d4a44c56 authored by Sietse Ringers's avatar Sietse Ringers

refactor: simplify RevocationStorage.Accumulator() function signature

parent 34dafe65
......@@ -124,20 +124,22 @@ func TestRevocationAll(t *testing.T) {
StartIrmaServer(t, false)
startRevocationServer(t)
_, acc, err := revocationConfiguration.IrmaConfiguration.Revocation.Accumulator(revocationTestCred, 2)
sacc, err := revocationConfiguration.IrmaConfiguration.Revocation.Accumulator(revocationTestCred, 2)
require.NoError(t, err)
acctime := acc.Time
acctime := sacc.Accumulator.Time
time.Sleep(time.Second)
// run scheduled update of accumulator, triggering POSTing it to our IRMA server
// run scheduled update of accumulator, triggering a POST to our IRMA server
revocationConfiguration.IrmaConfiguration.Scheduler.RunAll()
// give request time to be processed
time.Sleep(100 * time.Millisecond)
sacc1, acc, err := revocationConfiguration.IrmaConfiguration.Revocation.Accumulator(revocationTestCred, 2)
sacc1, err := revocationConfiguration.IrmaConfiguration.Revocation.Accumulator(revocationTestCred, 2)
require.NoError(t, err)
require.True(t, acc.Time > acctime)
require.True(t, sacc1.Accumulator.Time > acctime)
sacc2, acc2, err := irmaServerConfiguration.IrmaConfiguration.Revocation.Accumulator(revocationTestCred, 2)
require.Equal(t, acc, acc2)
sacc2, err := irmaServerConfiguration.IrmaConfiguration.Revocation.Accumulator(revocationTestCred, 2)
require.NoError(t, err)
require.Equal(t, sacc1, sacc2)
})
......@@ -314,9 +316,9 @@ func revoke(t *testing.T, key string, conf *irma.RevocationStorage, cred irma.Cr
ValidUntil: time.Now().Add(1 * time.Hour).UnixNano(),
}))
require.NoError(t, conf.Revoke(cred, key))
_, newacc, err := conf.Accumulator(cred, 2)
sacc, err := conf.Accumulator(cred, 2)
require.NoError(t, err)
*acc = *newacc
*acc = *sacc.Accumulator
}
func revocationConf(t *testing.T) *server.Configuration {
......
......@@ -176,7 +176,7 @@ func (rs *RevocationStorage) UpdateFrom(typ CredentialTypeIdentifier, pkcounter
// Only requires SQL implementation
var update *revocation.Update
if err := rs.db.Transaction(func(tx revStorage) error {
acc, _, err := rs.accumulator(tx, typ, pkcounter)
acc, err := rs.accumulator(tx, typ, pkcounter)
if err != nil {
return err
}
......@@ -343,13 +343,14 @@ func (rs *RevocationStorage) Revoke(typ CredentialTypeIdentifier, key string) er
}
func (rs *RevocationStorage) revokeAttr(tx revStorage, typ CredentialTypeIdentifier, sk *revocation.PrivateKey, e *RevocationAttribute) error {
_, cur, err := rs.accumulator(tx, typ, sk.Counter)
sacc, err := rs.accumulator(tx, typ, sk.Counter)
if err != nil {
return err
}
if cur == nil {
if sacc == nil {
return errors.Errorf("cannot revoke for type %s, not enabled yet", typ)
}
cur := sacc.Accumulator
var parent EventRecord
if err = rs.db.Last(&parent, map[string]interface{}{"cred_type": typ, "pk_counter": sk.Counter}); err != nil {
return err
......@@ -368,14 +369,14 @@ func (rs *RevocationStorage) revokeAttr(tx revStorage, typ CredentialTypeIdentif
// Accumulator methods
func (rs *RevocationStorage) Accumulator(typ CredentialTypeIdentifier, pkcounter uint) (
*revocation.SignedAccumulator, *revocation.Accumulator, error,
*revocation.SignedAccumulator, error,
) {
return rs.accumulator(rs.db, typ, pkcounter)
}
// accumulator retrieves, verifies and deserializes the accumulator of the given type and key.
func (rs *RevocationStorage) accumulator(tx revStorage, typ CredentialTypeIdentifier, pkcounter uint) (
*revocation.SignedAccumulator, *revocation.Accumulator, error,
*revocation.SignedAccumulator, error,
) {
var err error
var sacc *revocation.SignedAccumulator
......@@ -383,26 +384,26 @@ func (rs *RevocationStorage) accumulator(tx revStorage, typ CredentialTypeIdenti
record := &AccumulatorRecord{}
if err = tx.Last(record, map[string]interface{}{"cred_type": typ, "pk_counter": pkcounter}); err != nil {
if gorm.IsRecordNotFoundError(err) {
return nil, nil, nil
return nil, nil
}
}
sacc = record.SignedAccumulator()
} else {
sacc = rs.memdb.SignedAccumulator(typ, pkcounter)
if sacc == nil {
return nil, nil, nil
return nil, nil
}
}
pk, err := rs.Keys.PublicKey(typ.IssuerIdentifier(), sacc.PKCounter)
if err != nil {
return nil, nil, err
return nil, err
}
acc, err := sacc.UnmarshalVerify(pk)
_, err = sacc.UnmarshalVerify(pk)
if err != nil {
return nil, nil, err
return nil, err
}
return sacc, acc, nil
return sacc, nil
}
// Methods to update from remote revocation server
......
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