-
Notifications
You must be signed in to change notification settings - Fork 1
/
mock_milenage.go
37 lines (30 loc) · 1.04 KB
/
mock_milenage.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
/*
Copyright 2022 The Magma Authors.
This source code is licensed under the BSD-style license found in the
LICENSE file in the root directory of this source tree.
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package milenage
import "fmt"
// mockRNG yields a constant byte sequence instead of generating a new random sequence each time
type mockRNG []byte
func (rng mockRNG) Read(b []byte) (int, error) {
copy(b, rng)
if len(b) <= len(rng) {
return len(b), nil
}
return len(rng), fmt.Errorf("not enough data to read")
}
// NewMockCipher instantiates the Milenage algo using non-mutable mockRNG for rng
func NewMockCipher(amf []byte, rand []byte) (*Cipher, error) {
cipher, err := NewCipher(amf)
if err != nil {
return nil, err
}
cipher.SetRng(mockRNG(rand))
return cipher, nil
}