Skip to main content

TempPlaintext

Struct TempPlaintext 

Source
pub struct TempPlaintext { /* private fields */ }
Expand description

受控的临时明文文件,用于「以外部应用打开」。

§这个类型在防什么

把解密后的明文落盘给外部程序打开,会踩到三个旁路泄露 (见 docs/research/07-platform-and-sidechannels.md §3):

编号泄露本类型的对策
L2明文文件残留Drop 时删除;先覆写再删除(见下)
L3系统缩略图缓存目录写入 desktop.ini(Windows)
L5搜索索引收录明文内容目录标记不索引

§⚠️ 覆写删除的真实效力

TempPlaintext::shred 会在删除前用随机字节覆写文件。在现代存储上这不保证 数据真正消失:SSD 的 wear leveling 会把写入重定向到新的物理块,日志式文件系统 (APFS/Btrfs/ZFS)可能保留旧版本,快照更是直接留存。

它能挡住的是「文件被删除后用常规恢复工具捞回来」,挡不住物理取证。 本项目威胁模型已排除物理取证(N2/N3),因此这是成本合适的措施—— 但不能向用户宣称“安全擦除“。

Implementations§

Source§

impl TempPlaintext

Source

pub fn create(dir: &Path, filename: &str, plaintext: &[u8]) -> Result<Self>

在指定目录下创建临时明文文件。

dir 应当是应用私有的受控目录,不要用系统 %TEMP%——那里可能被 云盘同步(L14)或备份系统(L13)覆盖。调用方负责选定安全目录。

filename 用于保留正确的扩展名,让外部应用能正确关联打开方式。

§Errors

创建目录或写入文件失败时返回 Error::Io。

Source

pub fn path(&self) -> &Path

明文文件路径,可交给外部应用。

Source

pub const fn set_shred_on_drop(&mut self, shred: bool)

关闭 drop 时的覆写(仅用于测试或用户显式选择更快的清理)。

Source

pub fn shred(&self) -> Result<()>

覆写并删除文件。

关于效力边界见类型文档。

§Errors

覆写或删除失败时返回 Error::Io。

Trait Implementations§

Source§

impl Debug for TempPlaintext

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Drop for TempPlaintext

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.