Jooyung Han | 347d9f2 | 2021-05-28 00:05:14 +0900 | [diff] [blame] | 1 | // Copyright 2021, The Android Open Source Project |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
| 15 | //! MicrodroidSignature from /dev/block/by-name/signature |
| 16 | //! TODO(jooyung): migrate to "metadata" partition |
| 17 | |
| 18 | use log::info; |
| 19 | use microdroid_signature::microdroid_signature::MicrodroidSignature; |
| 20 | use protobuf::Message; |
| 21 | use std::fs::File; |
| 22 | use std::io; |
| 23 | use std::io::Read; |
| 24 | |
| 25 | const SIGNATURE_PATH: &str = "/dev/block/by-name/signature"; |
| 26 | |
| 27 | /// loads microdroid_signature from /dev/block/by-name/signature |
| 28 | pub fn load() -> io::Result<MicrodroidSignature> { |
| 29 | info!("loading signature..."); |
| 30 | |
| 31 | let mut f = File::open(SIGNATURE_PATH)?; |
| 32 | // signature partition is |
| 33 | // 4 bytes : size(N) in big endian |
| 34 | // N bytes : message for MicrodroidSignature |
| 35 | let mut buf = [0u8; 4]; |
| 36 | f.read_exact(&mut buf)?; |
| 37 | let size = i32::from_be_bytes(buf); |
| 38 | |
| 39 | Ok(MicrodroidSignature::parse_from_reader(&mut f.take(size as u64))?) |
| 40 | } |