Quellcodebibliothek Statistik Leitseite products/Sources/formale Sprachen/C/Firefox/security/ct/tests/gtest/   (Firefox Browser Version 153.0.1©)  Datei vom 27.6.2026 mit Größe 5 kB image not shown  

Quelle  BTSerializationTest.cpp

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


#include "BTVerifier.h"
#include "CTTestUtils.h"
#include "gtest/gtest.h"

namespace mozilla {
namespace ct {

using namespace pkix;

class BTSerializationTest : public ::testing::Test {
 public:
  void SetUp() override {
    mTestInclusionProof = GetTestInclusionProof();
    mTestInclusionProofUnexpectedData = GetTestInclusionProofUnexpectedData();
    mTestInclusionProofInvalidHashSize = GetTestInclusionProofInvalidHashSize();
    mTestInclusionProofInvalidHash = GetTestInclusionProofInvalidHash();
    mTestInclusionProofMissingLogId = GetTestInclusionProofMissingLogId();
    mTestInclusionProofNullPathLength = GetTestInclusionProofNullPathLength();
    mTestInclusionProofPathLengthTooSmall =
        GetTestInclusionProofPathLengthTooSmall();
    mTestInclusionProofPathLengthTooLarge =
        GetTestInclusionProofPathLengthTooLarge();
    mTestInclusionProofNullTreeSize = GetTestInclusionProofNullTreeSize();
    mTestInclusionProofLeafIndexOutOfBounds =
        GetTestInclusionProofLeafIndexOutOfBounds();
    mTestInclusionProofExtraData = GetTestInclusionProofExtraData();
  }

 protected:
  Buffer mTestInclusionProof;
  Buffer mTestInclusionProofUnexpectedData;
  Buffer mTestInclusionProofInvalidHashSize;
  Buffer mTestInclusionProofInvalidHash;
  Buffer mTestInclusionProofMissingLogId;
  Buffer mTestInclusionProofNullPathLength;
  Buffer mTestInclusionProofPathLengthTooSmall;
  Buffer mTestInclusionProofPathLengthTooLarge;
  Buffer mTestInclusionProofNullTreeSize;
  Buffer mTestInclusionProofLeafIndexOutOfBounds;
  Buffer mTestInclusionProofExtraData;
};

TEST_F(BTSerializationTest, DecodesInclusionProof) {
  const uint64_t expectedTreeSize = 4;
  const uint64_t expectedLeafIndex = 2;
  const uint64_t expectedInclusionPathElements = 2;

  Buffer expectedLogId = {0x01, 0x00};

  Input encodedProofInput = InputForBuffer(mTestInclusionProof);
  InclusionProofDataV2 ipr;
  ASSERT_EQ(Success, DecodeInclusionProof(encodedProofInput, ipr));
  EXPECT_EQ(expectedLogId, ipr.logId);
  EXPECT_EQ(expectedTreeSize, ipr.treeSize);
  EXPECT_EQ(expectedLeafIndex, ipr.leafIndex);
  EXPECT_EQ(expectedInclusionPathElements, ipr.inclusionPath.size());
  EXPECT_EQ(GetTestNodeHash0(), ipr.inclusionPath[0]);
  EXPECT_EQ(GetTestNodeHash1(), ipr.inclusionPath[1]);
}

TEST_F(BTSerializationTest, FailsDecodingInclusionProofUnexpectedData) {
  Input encodedProofInput = InputForBuffer(mTestInclusionProofUnexpectedData);
  InclusionProofDataV2 ipr;
  ASSERT_EQ(pkix::Result::ERROR_BAD_DER,
            DecodeInclusionProof(encodedProofInput, ipr));
}

TEST_F(BTSerializationTest, FailsDecodingInvalidHashSize) {
  Input encodedProofInput = InputForBuffer(mTestInclusionProofInvalidHashSize);
  InclusionProofDataV2 ipr;
  ASSERT_EQ(pkix::Result::ERROR_BAD_DER,
            DecodeInclusionProof(encodedProofInput, ipr));
}

TEST_F(BTSerializationTest, FailsDecodingInvalidHash) {
  Input encodedProofInput = InputForBuffer(mTestInclusionProofInvalidHash);
  InclusionProofDataV2 ipr;
  ASSERT_EQ(pkix::Result::ERROR_BAD_DER,
            DecodeInclusionProof(encodedProofInput, ipr));
}

TEST_F(BTSerializationTest, FailsDecodingMissingLogId) {
  Input encodedProofInput = InputForBuffer(mTestInclusionProofMissingLogId);
  InclusionProofDataV2 ipr;
  ASSERT_EQ(pkix::Result::ERROR_BAD_DER,
            DecodeInclusionProof(encodedProofInput, ipr));
}

TEST_F(BTSerializationTest, FailsDecodingNullPathLength) {
  Input encodedProofInput = InputForBuffer(mTestInclusionProofNullPathLength);
  InclusionProofDataV2 ipr;
  ASSERT_EQ(pkix::Result::ERROR_BAD_DER,
            DecodeInclusionProof(encodedProofInput, ipr));
}

TEST_F(BTSerializationTest, FailsDecodingPathLengthTooSmall) {
  Input encodedProofInput =
      InputForBuffer(mTestInclusionProofPathLengthTooSmall);
  InclusionProofDataV2 ipr;
  ASSERT_EQ(pkix::Result::ERROR_BAD_DER,
            DecodeInclusionProof(encodedProofInput, ipr));
}

TEST_F(BTSerializationTest, FailsDecodingPathLengthTooLarge) {
  Input encodedProofInput =
      InputForBuffer(mTestInclusionProofPathLengthTooLarge);
  InclusionProofDataV2 ipr;
  ASSERT_EQ(pkix::Result::ERROR_BAD_DER,
            DecodeInclusionProof(encodedProofInput, ipr));
}

TEST_F(BTSerializationTest, FailsDecodingNullTreeSize) {
  Input encodedProofInput = InputForBuffer(mTestInclusionProofNullTreeSize);
  InclusionProofDataV2 ipr;
  ASSERT_EQ(pkix::Result::ERROR_BAD_DER,
            DecodeInclusionProof(encodedProofInput, ipr));
}

TEST_F(BTSerializationTest, FailsDecodingLeafIndexOutOfBounds) {
  Input encodedProofInput =
      InputForBuffer(mTestInclusionProofLeafIndexOutOfBounds);
  InclusionProofDataV2 ipr;
  ASSERT_EQ(pkix::Result::ERROR_BAD_DER,
            DecodeInclusionProof(encodedProofInput, ipr));
}

TEST_F(BTSerializationTest, FailsDecodingExtraData) {
  Input encodedProofInput = InputForBuffer(mTestInclusionProofExtraData);
  InclusionProofDataV2 ipr;
  ASSERT_EQ(pkix::Result::ERROR_BAD_DER,
            DecodeInclusionProof(encodedProofInput, ipr));
}
}  // namespace ct
}  // namespace mozilla

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

¤ Dauer der Verarbeitung: 0.4 Sekunden  ¤

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