crypto_generic/
always_panic_impl.rs

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
10use std::io::Read;
11use std::io::Seek;
12use std::io::Write;
13
14use crate::CryptKey;
15
16/// Interface used for file encryption.
17pub struct CryptWriter<T: Write> {
18    _writer: T,
19}
20
21impl<T: Write> CryptWriter<T> {
22    /// Creates a new writer using an internally randomly generated key.
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).
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
38impl<T: Write> Write for CryptWriter<T> {
39    fn write(&mut self, _buf: &[u8]) -> std::io::Result<usize> {
40        panic!("no crypto support was compiled in this build");
41    }
42
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.
49pub struct CryptReader<T: Read + Seek> {
50    _reader: T,
51}
52
53impl<T> CryptReader<T>
54where
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.
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.
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
69impl<T> Read for CryptReader<T>
70where
71    T: Read + Seek,
72{
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`.
79pub fn generate_random_key() -> CryptKey {
80    panic!("no crypto support was compiled in this build");
81}