LCOV - code coverage report
Current view: top level - security/certverifier - SignedCertificateTimestamp.h (source / functions) Hit Total Coverage
Test: output.info Lines: 4 12 33.3 %
Date: 2017-07-14 16:53:18 Functions: 1 12 8.3 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
       2             : /* vim: set ts=8 sts=2 et sw=2 tw=80: */
       3             : /* This Source Code Form is subject to the terms of the Mozilla Public
       4             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       5             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
       6             : 
       7             : #ifndef SignedCertificateTimestamp_h
       8             : #define SignedCertificateTimestamp_h
       9             : 
      10             : #include "mozilla/Vector.h"
      11             : #include "pkix/Input.h"
      12             : #include "pkix/Result.h"
      13             : 
      14             : // Structures related to Certificate Transparency (RFC 6962).
      15             : namespace mozilla { namespace ct {
      16             : 
      17             : typedef Vector<uint8_t> Buffer;
      18             : 
      19             : // LogEntry struct in RFC 6962, Section 3.1.
      20           0 : struct LogEntry
      21             : {
      22             : 
      23             :   // LogEntryType enum in RFC 6962, Section 3.1.
      24             :   enum class Type {
      25             :     X509 = 0,
      26             :     Precert = 1
      27             :   };
      28             : 
      29             :   void Reset();
      30             : 
      31             :   Type type;
      32             : 
      33             :   // Set if type == X509.
      34             :   Buffer leafCertificate;
      35             : 
      36             :   // Set if type == Precert.
      37             :   Buffer issuerKeyHash;
      38             :   Buffer tbsCertificate;
      39             : };
      40             : 
      41             : // Helper structure to represent Digitally Signed data, as described in
      42             : // Sections 4.7 and 7.4.1.4.1 of RFC 5246.
      43           0 : struct DigitallySigned
      44             : {
      45             :   enum class HashAlgorithm {
      46             :     None = 0,
      47             :     MD5 = 1,
      48             :     SHA1 = 2,
      49             :     SHA224 = 3,
      50             :     SHA256 = 4,
      51             :     SHA384 = 5,
      52             :     SHA512 = 6,
      53             :   };
      54             : 
      55             :   enum class SignatureAlgorithm {
      56             :     Anonymous = 0,
      57             :     RSA = 1,
      58             :     DSA = 2,
      59             :     ECDSA = 3
      60             :   };
      61             : 
      62             :   // Returns true if |aHashAlgorithm| and |aSignatureAlgorithm|
      63             :   // match this DigitallySigned hash and signature algorithms.
      64             :   bool SignatureParametersMatch(HashAlgorithm aHashAlgorithm,
      65             :                                 SignatureAlgorithm aSignatureAlgorithm) const;
      66             : 
      67             :   HashAlgorithm hashAlgorithm;
      68             :   SignatureAlgorithm signatureAlgorithm;
      69             :   // 'signature' field.
      70             :   Buffer signatureData;
      71             : };
      72             : 
      73             : // SignedCertificateTimestamp struct in RFC 6962, Section 3.2.
      74           0 : struct SignedCertificateTimestamp
      75             : {
      76             :   // Version enum in RFC 6962, Section 3.2.
      77             :   enum class Version {
      78             :     V1 = 0,
      79             :   };
      80             : 
      81             :   Version version;
      82             :   Buffer logId;
      83             :   // "timestamp" is the current time in milliseconds, measured since the epoch,
      84             :   // ignoring leap seconds. See RFC 6962, Section 3.2.
      85             :   uint64_t timestamp;
      86             :   Buffer extensions;
      87             :   DigitallySigned signature;
      88             : };
      89             : 
      90           0 : inline pkix::Result BufferToInput(const Buffer& buffer, pkix::Input& input)
      91             : {
      92           0 :   if (buffer.length() == 0) {
      93           0 :     return pkix::Result::FATAL_ERROR_LIBRARY_FAILURE;
      94             :   }
      95           0 :   return input.Init(buffer.begin(), buffer.length());
      96             : }
      97             : 
      98          15 : inline pkix::Result InputToBuffer(pkix::Input input, Buffer& buffer)
      99             : {
     100          15 :   buffer.clear();
     101          15 :   if (!buffer.append(input.UnsafeGetData(), input.GetLength())) {
     102           0 :     return pkix::Result::FATAL_ERROR_NO_MEMORY;
     103             :   }
     104          15 :   return pkix::Success;
     105             : }
     106             : 
     107             : } } // namespace mozilla::ct
     108             : 
     109             : namespace mozilla {
     110             : 
     111             : // Comparison operators are placed under mozilla namespace since
     112             : // mozilla::ct::Buffer is actually mozilla::Vector.
     113             : bool operator==(const ct::Buffer& a, const ct::Buffer& b);
     114             : bool operator!=(const ct::Buffer& a, const ct::Buffer& b);
     115             : 
     116             : } // namespace mozilla
     117             : 
     118             : #endif // SignedCertificateTimestamp_h

Generated by: LCOV version 1.13