Eine aufbereitete Darstellung der Quelle

 
     
 
 
Anforderungen  |   Konzepte  |   Entwurf  |   Entwicklung  |   Qualitätssicherung  |   Lebenszyklus  |   Steuerung
 
 
 
 

Benutzer

Quelle  collection_keys.rs

  Sprache: Rust
 

/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */


use crate::error::Result;
use crate::record_types::CryptoKeysRecord;
use crate::{EncryptedPayload, KeyBundle, ServerTimestamp};
use std::collections::HashMap;

#[derive(Clone, Debug, PartialEq, Eq)]
pub struct CollectionKeys {
    pub timestamp: ServerTimestamp,
    pub default: KeyBundle,
    pub collections: HashMap<String, KeyBundle>,
}

impl CollectionKeys {
    pub fn new_random() -> Result<CollectionKeys> {
        let default = KeyBundle::new_random()?;
        Ok(CollectionKeys {
            timestamp: ServerTimestamp(0),
            default,
            collections: HashMap::new(),
        })
    }

    pub fn from_encrypted_payload(
        record: EncryptedPayload,
        timestamp: ServerTimestamp,
        root_key: &KeyBundle,
    ) -> Result<CollectionKeys> {
        let keys: CryptoKeysRecord = record.decrypt_into(root_key)?;
        Ok(CollectionKeys {
            timestamp,
            default: KeyBundle::from_base64(&keys.default[0], &keys.default[1])?,
            collections: keys
                .collections
                .into_iter()
                .map(|kv| Ok((kv.0, KeyBundle::from_base64(&kv.1[0], &kv.le='color: green'>1[1])?)))
                .collect::<Result<HashMap<String, KeyBundle>>>()?,
        })
    }

    pub fn to_encrypted_payload(&self, root_key: &KeyBundle) -> Result<EncryptedPayload> {
        let record = CryptoKeysRecord {
            id: "keys".into(),
            collection: "crypto".into(),
            default: self.default.to_b64_array(),
            collections: self
                .collections
                .iter()
                .map(|kv| (kv.0.clone(), kv.1.to_b64_array()))
                .collect(),
        };
        EncryptedPayload::from_cleartext_payload(root_key, &record)
    }

    pub fn key_for_collection<'a>(&'self, collection: &str) -> &'a KeyBundle {
        self.collections.get(collection).unwrap_or(&self.default)
    }
}

Messung V0.5 in Prozent
C=99 H=100 G=99

¤ Dauer der Verarbeitung: 0.12 Sekunden  (vorverarbeitet am  2026-06-18) ¤

*© Formatika GbR, Deutschland






Wurzel

Suchen

PVS Prover

Isabelle Prover

NIST Cobol Testsuite

Cephes Mathematical Library

Vienna Development Method

Haftungshinweis

Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.

Bemerkung:

Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.






                                                                                                                                                                                                                                                                                                                                                                                                     


Neuigkeiten

     Aktuelles
     Motto des Tages

Software

     Quellcodebibliothek
     Eigene Quellcodes
     Fremde Quellcodes
     Suchen

Aktivitäten

     Artikel über Sicherheit
     Anleitung zur Aktivierung von SSL

Muße

     Gedichte
     Musik
     Bilder

Jenseits des Üblichen ....
    

Besucherstatistik

Besucherstatistik