CryptoKey.h 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. namespace Web::Crypto {
  13. class CryptoKey final : public Bindings::PlatformObject {
  14. WEB_PLATFORM_OBJECT(CryptoKey, Bindings::PlatformObject);
  15. JS_DECLARE_ALLOCATOR(CryptoKey);
  16. public:
  17. [[nodiscard]] static JS::NonnullGCPtr<CryptoKey> create(JS::Realm&);
  18. virtual ~CryptoKey() override;
  19. bool extractable() const { return m_extractable; }
  20. Bindings::KeyType type() const { return m_type; }
  21. Object const* algorithm() const { return m_algorithm.ptr(); }
  22. Object const* usages() const { return m_usages.ptr(); }
  23. void set_extractable(bool extractable) { m_extractable = extractable; }
  24. void set_type(Bindings::KeyType type) { m_type = type; }
  25. void set_algorithm(JS::NonnullGCPtr<Object> algorithm) { m_algorithm = move(algorithm); }
  26. void set_usages(JS::NonnullGCPtr<Object> usages) { m_usages = move(usages); }
  27. private:
  28. explicit CryptoKey(JS::Realm&);
  29. virtual void initialize(JS::Realm&) override;
  30. virtual void visit_edges(Visitor&) override;
  31. Bindings::KeyType m_type;
  32. bool m_extractable { false };
  33. JS::NonnullGCPtr<Object> m_algorithm;
  34. JS::NonnullGCPtr<Object> m_usages;
  35. };
  36. }