Crypto.h 1012 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. /*
  2. * Copyright (c) 2021, Idan Horowitz <idan.horowitz@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <LibWeb/Bindings/PlatformObject.h>
  8. #include <LibWeb/Crypto/SubtleCrypto.h>
  9. #include <LibWeb/WebIDL/ExceptionOr.h>
  10. namespace Web::Crypto {
  11. class Crypto : public Bindings::PlatformObject {
  12. WEB_PLATFORM_OBJECT(Crypto, Bindings::PlatformObject);
  13. JS_DECLARE_ALLOCATOR(Crypto);
  14. public:
  15. [[nodiscard]] static JS::NonnullGCPtr<Crypto> create(JS::Realm&);
  16. virtual ~Crypto() override;
  17. JS::NonnullGCPtr<SubtleCrypto> subtle() const;
  18. WebIDL::ExceptionOr<JS::Handle<WebIDL::ArrayBufferView>> get_random_values(JS::Handle<WebIDL::ArrayBufferView>) const;
  19. WebIDL::ExceptionOr<String> random_uuid() const;
  20. protected:
  21. virtual void initialize(JS::Realm&) override;
  22. virtual void visit_edges(Cell::Visitor&) override;
  23. private:
  24. explicit Crypto(JS::Realm&);
  25. JS::GCPtr<SubtleCrypto> m_subtle;
  26. };
  27. ErrorOr<String> generate_random_uuid();
  28. }