MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / finish

Method finish

nodedb-array/src/segment/writer.rs:92–110  ·  view source on GitHub ↗

Finalise the segment by appending the footer + trailer. Consumes the writer and returns the complete byte vector. When `kek` is `Some`, the assembled plaintext buffer is wrapped in an AES-256-GCM `SEGA` envelope before being returned. When `None`, the raw `NDAS` segment bytes are returned.

(
        mut self,
        kek: Option<&nodedb_wal::crypto::WalEncryptionKey>,
    )

Source from the content-addressed store, hash-verified

90 /// AES-256-GCM `SEGA` envelope before being returned. When `None`, the
91 /// raw `NDAS` segment bytes are returned.
92 pub fn finish(
93 mut self,
94 kek: Option<&nodedb_wal::crypto::WalEncryptionKey>,
95 ) -> ArrayResult<Vec<u8>> {
96 if self.finished {
97 return Err(ArrayError::SegmentCorruption {
98 detail: "SegmentWriter::finish called twice".into(),
99 });
100 }
101 let footer = SegmentFooter::new(self.schema_hash, std::mem::take(&mut self.entries));
102 footer.encode_to(&mut self.buf)?;
103 self.finished = true;
104
105 if let Some(key) = kek {
106 return super::encrypt::encrypt_segment(key, &self.buf);
107 }
108
109 Ok(self.buf)
110 }
111
112 pub fn header_size(&self) -> usize {
113 HEADER_SIZE

Calls 3

takeFunction · 0.85
encrypt_segmentFunction · 0.70
encode_toMethod · 0.45