mirror of
https://github.com/rustfs/rustfs.git
synced 2026-09-06 03:59:14 +00:00
fix: use BTreeMap for deterministic encryption context serialization
SealScope::encryption_context() returned a HashMap whose key order is non-deterministic. The FakeSealer test round-trips the context through JSON serialization, and HashMap's random iteration order caused the prefix comparison to intermittently fail with 'encryption context mismatch'. Switch to BTreeMap which guarantees stable key ordering.
This commit is contained in:
@@ -28,7 +28,7 @@
|
||||
|
||||
use async_trait::async_trait;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::collections::HashMap;
|
||||
use std::collections::BTreeMap;
|
||||
use std::fmt;
|
||||
use std::sync::{Arc, OnceLock};
|
||||
|
||||
@@ -81,8 +81,8 @@ impl SealScope {
|
||||
/// The encryption context handed to the sealer. Keys are stable: they are
|
||||
/// part of the on-disk contract, because a ciphertext only decrypts under
|
||||
/// the same context.
|
||||
pub fn encryption_context(&self) -> HashMap<String, String> {
|
||||
HashMap::from([
|
||||
pub fn encryption_context(&self) -> BTreeMap<String, String> {
|
||||
BTreeMap::from([
|
||||
("rustfs:store".to_string(), self.store.as_str().to_string()),
|
||||
("rustfs:owner".to_string(), self.owner.clone()),
|
||||
("rustfs:field".to_string(), self.field.to_string()),
|
||||
@@ -206,7 +206,7 @@ mod tests {
|
||||
/// with, and refuses a ciphertext presented under a different one.
|
||||
#[derive(Default)]
|
||||
struct FakeSealer {
|
||||
sealed_contexts: Mutex<Vec<HashMap<String, String>>>,
|
||||
sealed_contexts: Mutex<Vec<BTreeMap<String, String>>>,
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
|
||||
Reference in New Issue
Block a user