pub struct PageStore { /* private fields */ }Expand description
Page store: maps logical page IDs to on-disk locations, with optional
at-rest encryption via EncryptionContext.
§On-disk layout
When encryption is disabled (passthrough mode), each page occupies
exactly page_size bytes at offset page_id * page_size.
When encryption is enabled, each page occupies page_size + 40 bytes
(the “encrypted stride”):
┌────────────────────────┬───────────────────────────────────┐
│ nonce (24 bytes) │ ciphertext + auth tag │
│ │ (page_size + 16 bytes) │
└────────────────────────┴───────────────────────────────────┘
total: page_size + 40 bytes per page slotThe encryption stride ensures that a file opened without a key cannot be accidentally decoded as raw pages (sizes won’t align).
Implementations§
Source§impl PageStore
impl PageStore
Sourcepub fn open(path: &Path) -> Result<Self>
pub fn open(path: &Path) -> Result<Self>
Open (or create) a page store at path with the given page_size and
no encryption.
Use PageStore::open_encrypted to enable at-rest encryption.
Sourcepub fn open_with_page_size(path: &Path, page_size: usize) -> Result<Self>
pub fn open_with_page_size(path: &Path, page_size: usize) -> Result<Self>
Open (or create) a page store with the given page size and no encryption.
Sourcepub fn open_encrypted(
path: &Path,
page_size: usize,
key: [u8; 32],
) -> Result<Self>
pub fn open_encrypted( path: &Path, page_size: usize, key: [u8; 32], ) -> Result<Self>
Open (or create) an encrypted page store.
key — 32-byte master encryption key (XChaCha20-Poly1305).
If the file already exists and was written with a different key, the
first read_page call will return
Error::EncryptionAuthFailed.
Sourcepub fn read_page(&self, id: PageId, buf: &mut [u8]) -> Result<()>
pub fn read_page(&self, id: PageId, buf: &mut [u8]) -> Result<()>
Read page id into buf.
buf must be exactly page_size bytes.
§Errors
Error::InvalidArgument—buf.len() != page_size.Error::EncryptionAuthFailed— AEAD tag rejected (wrong key or corrupted page).Error::Io— underlying I/O failure.
Sourcepub fn write_page(&self, id: PageId, buf: &[u8]) -> Result<()>
pub fn write_page(&self, id: PageId, buf: &[u8]) -> Result<()>
Write buf as page id.
buf must be exactly page_size bytes.
§Errors
Error::InvalidArgument—buf.len() != page_size.Error::Io— underlying I/O failure.