mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-09-08 16:58:38 +09:00
No Issue - Implement crypto.randomUUID
We already have code in the platform to generate random UUIDs. This simply exposes that functionality via the crypto.UUID function
This commit is contained in:
parent
48c27934c7
commit
9e6a0c089f
3 changed files with 27 additions and 0 deletions
|
|
@ -115,6 +115,27 @@ Crypto::GetRandomValues(JSContext* aCx, const ArrayBufferView& aArray,
|
||||||
aRetval.set(view);
|
aRetval.set(view);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Crypto::RandomUUID(nsAString& aRetVal)
|
||||||
|
{
|
||||||
|
// NSID_LENGTH == 39 == 36 UUID chars + 2 curly braces + 1 NUL byte
|
||||||
|
static_assert(NSID_LENGTH == 39);
|
||||||
|
|
||||||
|
nsCOMPtr<nsIUUIDGenerator> uuidgen =
|
||||||
|
do_GetService("@mozilla.org/uuid-generator;1");
|
||||||
|
|
||||||
|
nsID uuid;
|
||||||
|
|
||||||
|
nsresult rv = uuidgen->GenerateUUIDInPlace(&uuid);
|
||||||
|
|
||||||
|
char uuidBuffer[NSID_LENGTH];
|
||||||
|
uuid.ToProvidedString(uuidBuffer);
|
||||||
|
|
||||||
|
nsCString asciiString(uuidBuffer);
|
||||||
|
|
||||||
|
// Convert UUID chars to UTF-16 retval, omitting the curly braces and NUL
|
||||||
|
CopyASCIItoUTF16(Substring(asciiString, 1, NSID_LENGTH - 3), aRetVal);
|
||||||
|
}
|
||||||
|
|
||||||
SubtleCrypto*
|
SubtleCrypto*
|
||||||
Crypto::Subtle()
|
Crypto::Subtle()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@
|
||||||
#include "mozilla/dom/SubtleCrypto.h"
|
#include "mozilla/dom/SubtleCrypto.h"
|
||||||
#include "nsIGlobalObject.h"
|
#include "nsIGlobalObject.h"
|
||||||
|
|
||||||
|
#include "nsString.h"
|
||||||
#include "nsWrapperCache.h"
|
#include "nsWrapperCache.h"
|
||||||
#include "mozilla/dom/TypedArray.h"
|
#include "mozilla/dom/TypedArray.h"
|
||||||
#define NS_DOMCRYPTO_CID \
|
#define NS_DOMCRYPTO_CID \
|
||||||
|
|
@ -39,6 +40,8 @@ public:
|
||||||
JS::MutableHandle<JSObject*> aRetval,
|
JS::MutableHandle<JSObject*> aRetval,
|
||||||
ErrorResult& aRv);
|
ErrorResult& aRv);
|
||||||
|
|
||||||
|
void RandomUUID(nsAString& aRetVal);
|
||||||
|
|
||||||
SubtleCrypto*
|
SubtleCrypto*
|
||||||
Subtle();
|
Subtle();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -18,4 +18,7 @@ interface Crypto {
|
||||||
|
|
||||||
[Throws]
|
[Throws]
|
||||||
ArrayBufferView getRandomValues(ArrayBufferView array);
|
ArrayBufferView getRandomValues(ArrayBufferView array);
|
||||||
|
|
||||||
|
[SecureContext]
|
||||||
|
DOMString randomUUID();
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue