1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef mozilla_dom_CryptoBuffer_h
8 #define mozilla_dom_CryptoBuffer_h
12 #include "mozilla/dom/TypedArray.h"
14 namespace mozilla::dom
{
16 class ArrayBufferViewOrArrayBuffer
;
17 class OwningArrayBufferViewOrArrayBuffer
;
19 class CryptoBuffer
: public FallibleTArray
<uint8_t> {
21 uint8_t* Assign(const CryptoBuffer
& aData
);
22 uint8_t* Assign(const uint8_t* aData
, uint32_t aLength
);
23 uint8_t* Assign(const nsACString
& aString
);
24 uint8_t* Assign(const SECItem
* aItem
);
25 uint8_t* Assign(const nsTArray
<uint8_t>& aData
);
26 uint8_t* Assign(const ArrayBuffer
& aData
);
27 uint8_t* Assign(const ArrayBufferView
& aData
);
28 uint8_t* Assign(const ArrayBufferViewOrArrayBuffer
& aData
);
29 uint8_t* Assign(const OwningArrayBufferViewOrArrayBuffer
& aData
);
30 uint8_t* Assign(const Uint8Array
& aArray
);
32 uint8_t* AppendSECItem(const SECItem
* aItem
);
33 uint8_t* AppendSECItem(const SECItem
& aItem
);
35 nsresult
FromJwkBase64(const nsString
& aBase64
);
36 nsresult
ToJwkBase64(nsString
& aBase64
) const;
37 bool ToSECItem(PLArenaPool
* aArena
, SECItem
* aItem
) const;
38 JSObject
* ToUint8Array(JSContext
* aCx
, ErrorResult
& aError
) const;
39 JSObject
* ToArrayBuffer(JSContext
* aCx
, ErrorResult
& aError
) const;
41 bool GetBigIntValue(unsigned long& aRetVal
);
43 CryptoBuffer
InfallibleClone() const {
45 if (!result
.Assign(*this)) {
46 MOZ_CRASH("Out of memory");
52 } // namespace mozilla::dom
54 #endif // mozilla_dom_CryptoBuffer_h