Victor Hsieh | f77c572 | 2020-11-13 14:30:05 -0800 | [diff] [blame^] | 1 | /* |
| 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 | |
| 17 | use 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 | |
| 22 | pub trait Authenticator { |
| 23 | fn verify(&self, signature: &[u8], signed_data: &[u8]) -> io::Result<bool>; |
| 24 | } |
| 25 | |
| 26 | pub struct FakeAuthenticator { |
| 27 | should_allow: bool, |
| 28 | } |
| 29 | |
| 30 | #[allow(dead_code)] |
| 31 | impl 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 | |
| 41 | impl Authenticator for FakeAuthenticator { |
| 42 | fn verify(&self, _signature_pem: &[u8], _signed_data: &[u8]) -> io::Result<bool> { |
| 43 | Ok(self.should_allow) |
| 44 | } |
| 45 | } |