-
Notifications
You must be signed in to change notification settings - Fork 28
/
mock_revocation_manager.go
41 lines (32 loc) · 1.2 KB
/
mock_revocation_manager.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// Copyright 2015 The Vanadium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package revocation
import (
"time"
"v.io/v23/context"
)
func NewMockRevocationManager(ctx *context.T) RevocationManager {
revocationDB = &mockDatabase{make(map[string][]byte), make(map[string]*time.Time)}
return &revocationManager{ctx}
}
type mockDatabase struct {
tpCavIDToRevCavID map[string][]byte
revCavIDToTimestamp map[string]*time.Time
}
func (m *mockDatabase) InsertCaveat(thirdPartyCaveatID string, revocationCaveatID []byte) error {
m.tpCavIDToRevCavID[thirdPartyCaveatID] = revocationCaveatID
return nil
}
func (m *mockDatabase) Revoke(thirdPartyCaveatID string) error {
timestamp := time.Now()
m.revCavIDToTimestamp[string(m.tpCavIDToRevCavID[thirdPartyCaveatID])] = ×tamp
return nil
}
func (m *mockDatabase) IsRevoked(revocationCaveatID []byte) (bool, error) {
_, exists := m.revCavIDToTimestamp[string(revocationCaveatID)]
return exists, nil
}
func (m *mockDatabase) RevocationTime(thirdPartyCaveatID string) (*time.Time, error) {
return m.revCavIDToTimestamp[string(m.tpCavIDToRevCavID[thirdPartyCaveatID])], nil
}