blob: 71ad858baf0e2914d65593bd2f66aa2edfe51980 [file] [log] [blame]
Victor Hsiehf77c5722020-11-13 14:30:05 -08001/*
2 * Copyright (C) 2020 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17use std::io;
18
19// TODO(b/170494765): Implement an authenticator to verify a PKCS#7 signature. We only need to
20// verify the signature, not the full certificate chain.
21
22pub trait Authenticator {
23 fn verify(&self, signature: &[u8], signed_data: &[u8]) -> io::Result<bool>;
24}
25
26pub struct FakeAuthenticator {
27 should_allow: bool,
28}
29
30#[allow(dead_code)]
31impl FakeAuthenticator {
32 pub fn always_succeed() -> Self {
33 FakeAuthenticator { should_allow: true }
34 }
35
36 pub fn always_fail() -> Self {
37 FakeAuthenticator { should_allow: false }
38 }
39}
40
41impl Authenticator for FakeAuthenticator {
42 fn verify(&self, _signature_pem: &[u8], _signed_data: &[u8]) -> io::Result<bool> {
43 Ok(self.should_allow)
44 }
45}