1 // Copyright 2024 The ChromiumOS Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 //! Implements CryptReader/Writer by always panicking. Vendors are expected to
6 //! implement their own encryption schemes.
7
8 #![allow(dead_code)]
9
10 use std::io::Read;
11 use std::io::Seek;
12 use std::io::Write;
13
14 use crate::CryptKey;
15
16 /// Interface used for file encryption.
17 pub struct CryptWriter<T: Write> {
18 _writer: T,
19 }
20
21 impl<T: Write> CryptWriter<T> {
22 /// Creates a new writer using an internally randomly generated key.
new(_inner_writable: T, _chunk_size_bytes: usize) -> anyhow::Result<Box<Self>>23 pub fn new(_inner_writable: T, _chunk_size_bytes: usize) -> anyhow::Result<Box<Self>> {
24 panic!("no crypto support was compiled in this build");
25 }
26
27 /// Creates a new writer using the provided key and encrypted chunk size. Generally, larger
28 /// chunks are more performant but have buffering cost of O(chunk_size).
new_from_key( _inner_writable: T, _chunk_size_bytes: usize, _key: &CryptKey, ) -> anyhow::Result<Box<Self>>29 pub fn new_from_key(
30 _inner_writable: T,
31 _chunk_size_bytes: usize,
32 _key: &CryptKey,
33 ) -> anyhow::Result<Box<Self>> {
34 panic!("no crypto support was compiled in this build");
35 }
36 }
37
38 impl<T: Write> Write for CryptWriter<T> {
write(&mut self, _buf: &[u8]) -> std::io::Result<usize>39 fn write(&mut self, _buf: &[u8]) -> std::io::Result<usize> {
40 panic!("no crypto support was compiled in this build");
41 }
42
flush(&mut self) -> std::io::Result<()>43 fn flush(&mut self) -> std::io::Result<()> {
44 panic!("no crypto support was compiled in this build");
45 }
46 }
47
48 /// Interface used for file decryption.
49 pub struct CryptReader<T: Read + Seek> {
50 _reader: T,
51 }
52
53 impl<T> CryptReader<T>
54 where
55 T: Read + Seek,
56 {
57 /// Given a newly opened file previously written by a `CryptWriter`, extracts the encryption key
58 /// used to write the file.
extract_key(_inner_readable: T) -> anyhow::Result<CryptKey>59 pub fn extract_key(_inner_readable: T) -> anyhow::Result<CryptKey> {
60 panic!("no crypto support was compiled in this build");
61 }
62
63 /// Creates a CryptReader over a file given a key.
from_file_and_key(_inner_readable: T, _key: &CryptKey) -> anyhow::Result<Box<Self>>64 pub fn from_file_and_key(_inner_readable: T, _key: &CryptKey) -> anyhow::Result<Box<Self>> {
65 panic!("no crypto support was compiled in this build");
66 }
67 }
68
69 impl<T> Read for CryptReader<T>
70 where
71 T: Read + Seek,
72 {
read(&mut self, _buf: &mut [u8]) -> std::io::Result<usize>73 fn read(&mut self, _buf: &mut [u8]) -> std::io::Result<usize> {
74 panic!("no crypto support was compiled in this build");
75 }
76 }
77
78 /// Generates a random key usable with `CryptWriter` & `CryptReader`.
generate_random_key() -> CryptKey79 pub fn generate_random_key() -> CryptKey {
80 panic!("no crypto support was compiled in this build");
81 }
82