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_PrioEncoder_h
8 #define mozilla_dom_PrioEncoder_h
10 #include "mozilla/dom/PrioEncoderBinding.h"
11 #include "mozilla/dom/RootedDictionary.h"
13 class nsIGlobalObject
;
14 using SECKEYPublicKey
= struct SECKEYPublicKeyStr
;
15 using PublicKey
= SECKEYPublicKey
*;
22 NS_INLINE_DECL_REFCOUNTING(PrioEncoder
)
25 static nsresult
EncodeNative(const nsCString
& aBatchID
,
26 const nsTArray
<bool>& aData
, nsCString
& aResult
,
30 static void Encode(GlobalObject
& aGlobal
, const nsCString
& aBatchID
,
31 const PrioParams
& aPrioParams
,
32 RootedDictionary
<PrioEncodedData
>& aData
,
35 // maximum number of booleans that can be prio-encoded in a single batch.
36 const static uint32_t gNumBooleans
= 2046;
38 // Set (or, by passing nullptrs, reset) the keys used to encode the payloads.
39 static nsresult
SetKeys(const char* aKeyA
= nullptr,
40 const char* aKeyB
= nullptr);
46 static PublicKey sPublicKeyA
;
48 static PublicKey sPublicKeyB
;
50 static StaticRefPtr
<PrioEncoder
> sSingleton
;
52 static bool IsValidHexPublicKey(mozilla::Span
<const char>);
54 static nsresult
LazyInitSingleton();
58 } // namespace mozilla
60 #endif // mozilla_dom_PrioEncoder_h