CryptoKey.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /*
  2. * Copyright (c) 2023, stelar7 <dudedbz@gmail.com>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <LibJS/Forward.h>
  8. #include <LibJS/Heap/GCPtr.h>
  9. #include <LibWeb/Bindings/CryptoKeyPrototype.h>
  10. #include <LibWeb/Bindings/Intrinsics.h>
  11. #include <LibWeb/Bindings/PlatformObject.h>
  12. #include <LibWeb/Crypto/CryptoBindings.h>
  13. namespace Web::Crypto {
  14. class CryptoKey final : public Bindings::PlatformObject {
  15. WEB_PLATFORM_OBJECT(CryptoKey, Bindings::PlatformObject);
  16. JS_DECLARE_ALLOCATOR(CryptoKey);
  17. public:
  18. using InternalKeyData = Variant<ByteBuffer, Bindings::JsonWebKey>;
  19. [[nodiscard]] static JS::NonnullGCPtr<CryptoKey> create(JS::Realm&, InternalKeyData);
  20. virtual ~CryptoKey() override;
  21. bool extractable() const { return m_extractable; }
  22. Bindings::KeyType type() const { return m_type; }
  23. Object const* algorithm() const { return m_algorithm.ptr(); }
  24. Object const* usages() const { return m_usages.ptr(); }
  25. void set_extractable(bool extractable) { m_extractable = extractable; }
  26. void set_type(Bindings::KeyType type) { m_type = type; }
  27. void set_algorithm(JS::NonnullGCPtr<Object> algorithm) { m_algorithm = move(algorithm); }
  28. void set_usages(JS::NonnullGCPtr<Object> usages) { m_usages = move(usages); }
  29. private:
  30. CryptoKey(JS::Realm&, InternalKeyData);
  31. virtual void initialize(JS::Realm&) override;
  32. virtual void visit_edges(Visitor&) override;
  33. Bindings::KeyType m_type;
  34. bool m_extractable { false };
  35. JS::NonnullGCPtr<Object> m_algorithm;
  36. JS::NonnullGCPtr<Object> m_usages;
  37. InternalKeyData m_key_data;
  38. };
  39. }