blob: 4f0688535917c509fa6ed6568f5182357c1abeb1 [file] [log] [blame]
Jooyung Han347d9f22021-05-28 00:05:14 +09001// 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
18use log::info;
19use microdroid_signature::microdroid_signature::MicrodroidSignature;
20use protobuf::Message;
21use std::fs::File;
22use std::io;
23use std::io::Read;
24
25const SIGNATURE_PATH: &str = "/dev/block/by-name/signature";
26
27/// loads microdroid_signature from /dev/block/by-name/signature
28pub 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}