cast_cert_test_helpers.h 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. // Copyright 2020 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef COMPONENTS_CAST_CERTIFICATE_CAST_CERT_TEST_HELPERS_H_
  5. #define COMPONENTS_CAST_CERTIFICATE_CAST_CERT_TEST_HELPERS_H_
  6. #include <memory>
  7. #include <string>
  8. #include "base/files/file_path.h"
  9. #include "base/strings/string_piece.h"
  10. #include "base/time/time.h"
  11. #include "net/cert/pki/trust_store_in_memory.h"
  12. namespace cast_certificate {
  13. namespace testing {
  14. // Returns components/test/data/cast_certificate
  15. const base::FilePath& GetCastCertificateDirectory();
  16. // Returns components/test/data/cast_certificate/certificates
  17. const base::FilePath& GetCastCertificatesSubDirectory();
  18. // Helper structure that describes a message and its various signatures.
  19. struct SignatureTestData {
  20. std::string message;
  21. // RSASSA PKCS#1 v1.5 with SHA1.
  22. std::string signature_sha1;
  23. // RSASSA PKCS#1 v1.5 with SHA256.
  24. std::string signature_sha256;
  25. };
  26. // Reads a PEM file that contains "MESSAGE", "SIGNATURE SHA1" and
  27. // "SIGNATURE SHA256" blocks.
  28. // |file_name| should be relative to //components/test/data/cast_certificate
  29. SignatureTestData ReadSignatureTestData(const base::StringPiece& file_name);
  30. // Converts uint64_t unix timestamp in seconds to base::Time.
  31. base::Time ConvertUnixTimestampSeconds(uint64_t time);
  32. // Helper method that loads a certificate from the test certificates folder and
  33. // places it in an heap allocated trust store.
  34. std::unique_ptr<net::TrustStoreInMemory> LoadTestCert(
  35. const base::StringPiece& cert_file_name);
  36. } // namespace testing
  37. } // namespace cast_certificate
  38. #endif // COMPONENTS_CAST_CERTIFICATE_CAST_CERT_TEST_HELPERS_H_