xref: /aosp_15_r20/tools/security/remote_provisioning/hwtrust/cxxbridge/include/hwtrust/hwtrust.h (revision d9ecfb0f4d734c9ce41cde8ac4d585b094fd4222)
1 #pragma once
2 
3 #include <memory>
4 #include <vector>
5 
6 #include <android-base/result.h>
7 
8 using android::base::Error;
9 using android::base::Result;
10 
11 namespace hwtrust {
12 
13 class Csr;
14 
15 // Hide the details of the rust binding from clients with an opaque type.
16 struct BoxedDiceChain;
17 
18 class DiceChain final {
19 public:
20   friend Csr;
21 
22   enum class Kind {
23     kVsr13,
24     kVsr14,
25     kVsr15,
26     kVsr16,
27   };
28 
29   static Result<DiceChain> Verify(
30     const std::vector<uint8_t>& chain, DiceChain::Kind kind, bool allow_any_mode,
31     std::string_view instance) noexcept;
32 
33   ~DiceChain();
34   DiceChain(DiceChain&&) = default;
35 
36   Result<std::vector<std::vector<uint8_t>>> CosePublicKeys() const noexcept;
37 
38   bool IsProper() const noexcept;
39 
40 private:
41   DiceChain(std::unique_ptr<BoxedDiceChain> chain, size_t size) noexcept;
42 
43   std::unique_ptr<BoxedDiceChain> chain_;
44   size_t size_;
45 };
46 
47 struct BoxedCsr;
48 
49 class Csr final {
50 public:
51   static Result<Csr> validate(const std::vector<uint8_t>& csr, DiceChain::Kind kind,
52     bool allowAnyMode, std::string_view instance) noexcept;
53 
54   ~Csr();
55   Csr(Csr&&) = default;
56 
57   Result<DiceChain> getDiceChain() const noexcept;
58 
59   private:
60     Csr(std::unique_ptr<BoxedCsr> csr, DiceChain::Kind kind, std::string_view instance) noexcept;
61 
62     std::unique_ptr<BoxedCsr> mCsr;
63     const DiceChain::Kind mKind;
64     const std::string mInstance;
65 };
66 
67 } // namespace hwtrust
68