ciphertextLengthForPlaintext
ciphertextLengthForPlaintext(
plaintextLength,chunkSize):number
Defined in: packages/filecoin-encryption-envelope/src/chunk-layout.ts:175
Detached ciphertext length a plaintext of plaintextLength bytes produces
at chunkSize: P + 16 × max(1, ceil(P / S)), adding one 16-byte
(TAG_SIZE) authentication tag per chunk — including one tag even for empty
input (0).
Throws InvalidPlaintextLengthError if plaintextLength is not a
non-negative safe integer, if the implied ciphertext length is not a safe
integer, or if the detached ciphertext alone exceeds
MAX_ENCODED_OBJECT_SIZE. Throws InvalidChunkSizeError if chunkSize is
outside [MIN_CHUNK_SIZE, MAX_CHUNK_SIZE], or ChunkCountExceededError if
the chunk count exceeds MAX_CHUNK_COUNT.
The returned length covers only the detached ciphertext, not the COSE
envelope. For a full-object check against MAX_ENCODED_OBJECT_SIZE, add the
actual encoded envelope length (or MAX_ENVELOPE_SIZE as a conservative
upper bound when the envelope length is not known yet).
Internally, this is also what makes a declared plaintext_length checkable:
the mapping is strictly increasing in P, so one ciphertext length admits
exactly one valid P — which holds only because the profile permits a single
final-chunk form (see chunkLayout).
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
plaintextLength |
number |
chunkSize |
number |
Returns
Section titled “Returns”number