fromParts static method
Builds a SecureMessage
from raw components.
version
protocol version (must be >=1).
window
time window (non-negative).
nonce
8-byte random nonce (validated).
ciphertext
AES-256-CBC ciphertext bytes.
tag
32-byte HMAC-SHA256 tag.
Throws InvalidMessageException if any precondition fails.
Implementation
static SecureMessage fromParts({
required int version,
required int window,
required Uint8List nonce,
required Uint8List ciphertext,
required Uint8List tag,
}) {
try {
if (version < 1) {
throw ArgumentError.value(version, 'v', 'Protocol version must be >= 1.');
}
if (window < 0) {
throw ArgumentError.value(window, 'w', 'Window must be non-negative.');
}
NonceGenerator.validate(nonce);
if (ciphertext.isEmpty) {
throw ArgumentError('ciphertext must not be empty.');
}
if (tag.length != 32) {
throw ArgumentError.value(tag.length, 'tag.length', 'HMAC-SHA256 tag must be 32 bytes.');
}
// Store defensive copies to maintain immutability guarantees.
return SecureMessage._internal(
version: version,
window: window,
nonce: Uint8List.fromList(nonce),
ciphertext: Uint8List.fromList(ciphertext),
tag: Uint8List.fromList(tag),
);
} catch (e, st) {
throw InvalidMessageException(cause: e, stackTrace: st);
}
}