Eine aufbereitete Darstellung der Quelle

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

Benutzer

Quelle  CipherStrategyUtils.h

  Sprache: C
 

/* 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/. */


#ifndef DOM_QUOTA_CIPHERSTRATEGYUTILS_H_
#define DOM_QUOTA_CIPHERSTRATEGYUTILS_H_

#include <algorithm>
#include <array>
#include <cstddef>
#include <cstdint>

#include "ErrorList.h"
#include "ScopedNSSTypes.h"
#include "mozilla/Assertions.h"
#include "mozilla/Maybe.h"
#include "mozilla/Result.h"
#include "mozilla/ResultExtensions.h"
#include "mozilla/Span.h"
#include "pk11pub.h"

namespace mozilla::dom::quota {

template <typename KeyType>
Result<KeyType, nsresult> GenerateKey() {
  const auto slot = UniquePK11SlotInfo{PK11_GetInternalSlot()};
  if (slot == nullptr) {
    return Err(NS_ERROR_FAILURE);
  }
  const auto symKey = UniquePK11SymKey{PK11_KeyGen(
      slot.get(), CKM_CHACHA20_KEY_GEN, nullptr, sizeof(KeyType), nullptr)};
  if (symKey == nullptr) {
    return Err(NS_ERROR_FAILURE);
  }
  if (PK11_ExtractKeyValue(symKey.get()) != SECSuccess) {
    return Err(NS_ERROR_FAILURE);
  }
  // No need to free keyData as it is a buffer managed by symKey.
  SECItem* keyData = PK11_GetKeyData(symKey.get());
  if (keyData == nullptr) {
    return Err(NS_ERROR_FAILURE);
  }
  KeyType key;
  MOZ_RELEASE_ASSERT(keyData->len == key.size());
  std::copy(keyData->data, keyData->data + key.size(), key.data());
  return key;
}

template <size_t N>
std::array<uint8_t, N> MakeRandomData() {
  std::array<uint8_t, N> res;
  const auto rv = PK11_GenerateRandom(res.data(), res.size());
  /// XXX Allow return of error code to handle this gracefully.
  MOZ_RELEASE_ASSERT(rv == SECSuccess);
  return res;
}

template <typename KeyType>
Span<const uint8_t> SerializeKey(const KeyType& aKey) {
  return Span(aKey);
}

template <typename KeyType>
Maybe<KeyType> DeserializeKey(const Span<const uint8_t>& aSerializedKey) {
  KeyType res;
  if (res.size() != aSerializedKey.size()) {
    return Nothing();
  }
  std::copy(aSerializedKey.cbegin(), aSerializedKey.cend(), res.begin());
  return Some(res);
}

}  // namespace mozilla::dom::quota

#endif  // DOM_QUOTA_CIPHERSTRATEGYUTILS_H_

Messung V0.5 in Prozent
C=92 H=100 G=95

¤ Dauer der Verarbeitung: 0.24 Sekunden  (vorverarbeitet am  2026-08-25) ¤

*© 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

Open Source Software

     Quellcodebibliothek
     Eigene Quellcodes
     Fremde Quellcodes
     Suchen

Jenseits des Üblichen ....
    

Besucherstatistik

Besucherstatistik

Statistik
#Sources=141584
#Domains=752002