Bug 1026314 - Rename Key to CryptoKey in WebCrypto r=rbarnes,bz

--HG--
rename : dom/crypto/Key.cpp => dom/crypto/CryptoKey.cpp
rename : dom/crypto/Key.h => dom/crypto/CryptoKey.h
rename : dom/crypto/KeyPair.cpp => dom/crypto/CryptoKeyPair.cpp
rename : dom/crypto/KeyPair.h => dom/crypto/CryptoKeyPair.h
This commit is contained in:
Tim Taubert 2014-06-23 23:25:13 +02:00
parent 4b5c1ec146
commit 02d0c6d693
12 changed files with 178 additions and 178 deletions

View File

@ -46,7 +46,7 @@ SubtleCrypto::WrapObject(JSContext* aCx)
already_AddRefed<Promise>
SubtleCrypto::Encrypt(JSContext* cx,
const ObjectOrString& algorithm,
Key& key,
CryptoKey& key,
const CryptoOperationData& data)
{
SUBTLECRYPTO_METHOD_BODY(Encrypt, cx, algorithm, key, data)
@ -55,7 +55,7 @@ SubtleCrypto::Encrypt(JSContext* cx,
already_AddRefed<Promise>
SubtleCrypto::Decrypt(JSContext* cx,
const ObjectOrString& algorithm,
Key& key,
CryptoKey& key,
const CryptoOperationData& data)
{
SUBTLECRYPTO_METHOD_BODY(Decrypt, cx, algorithm, key, data)
@ -64,7 +64,7 @@ SubtleCrypto::Decrypt(JSContext* cx,
already_AddRefed<Promise>
SubtleCrypto::Sign(JSContext* cx,
const ObjectOrString& algorithm,
Key& key,
CryptoKey& key,
const CryptoOperationData& data)
{
SUBTLECRYPTO_METHOD_BODY(Sign, cx, algorithm, key, data)
@ -73,7 +73,7 @@ SubtleCrypto::Sign(JSContext* cx,
already_AddRefed<Promise>
SubtleCrypto::Verify(JSContext* cx,
const ObjectOrString& algorithm,
Key& key,
CryptoKey& key,
const CryptoOperationData& signature,
const CryptoOperationData& data)
{
@ -103,7 +103,7 @@ SubtleCrypto::ImportKey(JSContext* cx,
already_AddRefed<Promise>
SubtleCrypto::ExportKey(const nsAString& format,
Key& key)
CryptoKey& key)
{
SUBTLECRYPTO_METHOD_BODY(ExportKey, format, key)
}
@ -118,7 +118,7 @@ SubtleCrypto::GenerateKey(JSContext* cx, const ObjectOrString& algorithm,
already_AddRefed<Promise>
SubtleCrypto::DeriveKey(JSContext* cx,
const ObjectOrString& algorithm,
Key& baseKey,
CryptoKey& baseKey,
const ObjectOrString& derivedKeyType,
bool extractable, const Sequence<nsString>& keyUsages)
{
@ -129,7 +129,7 @@ SubtleCrypto::DeriveKey(JSContext* cx,
already_AddRefed<Promise>
SubtleCrypto::DeriveBits(JSContext* cx,
const ObjectOrString& algorithm,
Key& baseKey,
CryptoKey& baseKey,
uint32_t length)
{
SUBTLECRYPTO_METHOD_BODY(DeriveBits, cx, algorithm, baseKey, length)

View File

@ -11,7 +11,7 @@
#include "nsWrapperCache.h"
#include "nsPIDOMWindow.h"
#include "mozilla/dom/UnionTypes.h"
#include "mozilla/dom/Key.h"
#include "mozilla/dom/CryptoKey.h"
#include "js/TypeDecls.h"
namespace mozilla {
@ -43,22 +43,22 @@ public:
already_AddRefed<Promise> Encrypt(JSContext* cx,
const ObjectOrString& algorithm,
Key& key,
CryptoKey& key,
const CryptoOperationData& data);
already_AddRefed<Promise> Decrypt(JSContext* cx,
const ObjectOrString& algorithm,
Key& key,
CryptoKey& key,
const CryptoOperationData& data);
already_AddRefed<Promise> Sign(JSContext* cx,
const ObjectOrString& algorithm,
Key& key,
CryptoKey& key,
const CryptoOperationData& data);
already_AddRefed<Promise> Verify(JSContext* cx,
const ObjectOrString& algorithm,
Key& key,
CryptoKey& key,
const CryptoOperationData& signature,
const CryptoOperationData& data);
@ -73,7 +73,7 @@ public:
bool extractable,
const Sequence<nsString>& keyUsages);
already_AddRefed<Promise> ExportKey(const nsAString& format, Key& key);
already_AddRefed<Promise> ExportKey(const nsAString& format, CryptoKey& key);
already_AddRefed<Promise> GenerateKey(JSContext* cx,
const ObjectOrString& algorithm,
@ -82,14 +82,14 @@ public:
already_AddRefed<Promise> DeriveKey(JSContext* cx,
const ObjectOrString& algorithm,
Key& baseKey,
CryptoKey& baseKey,
const ObjectOrString& derivedKeyType,
bool extractable,
const Sequence<nsString>& keyUsages);
already_AddRefed<Promise> DeriveBits(JSContext* cx,
const ObjectOrString& algorithm,
Key& baseKey,
CryptoKey& baseKey,
uint32_t length);
private:

View File

@ -56,7 +56,7 @@
#include "mozilla/AutoRestore.h"
#include "mozilla/dom/ErrorEvent.h"
#include "mozilla/dom/ImageData.h"
#include "mozilla/dom/Key.h"
#include "mozilla/dom/CryptoKey.h"
#include "mozilla/dom/ImageDataBinding.h"
#include "mozilla/dom/SubtleCryptoBinding.h"
#include "nsAXPCNativeCallContext.h"
@ -2821,7 +2821,7 @@ NS_DOMReadStructuredClone(JSContext* cx,
// Prevent the return value from being trashed by a GC during ~nsRefPtr.
JS::Rooted<JSObject*> result(cx);
{
nsRefPtr<Key> key = new Key(global);
nsRefPtr<CryptoKey> key = new CryptoKey(global);
if (!key->ReadStructuredClone(reader)) {
result = nullptr;
} else {
@ -2859,8 +2859,8 @@ NS_DOMWriteStructuredClone(JSContext* cx,
}
// Handle Key cloning
Key* key;
if (NS_SUCCEEDED(UNWRAP_OBJECT(Key, obj, key))) {
CryptoKey* key;
if (NS_SUCCEEDED(UNWRAP_OBJECT(CryptoKey, obj, key))) {
return JS_WriteUint32Pair(writer, SCTAG_DOM_WEBCRYPTO_KEY, 0) &&
key->WriteStructuredClone(writer);
}

View File

@ -7,47 +7,47 @@
#include "pk11pub.h"
#include "cryptohi.h"
#include "ScopedNSSTypes.h"
#include "mozilla/dom/Key.h"
#include "mozilla/dom/CryptoKey.h"
#include "mozilla/dom/WebCryptoCommon.h"
#include "mozilla/dom/SubtleCryptoBinding.h"
namespace mozilla {
namespace dom {
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(Key, mGlobal, mAlgorithm)
NS_IMPL_CYCLE_COLLECTING_ADDREF(Key)
NS_IMPL_CYCLE_COLLECTING_RELEASE(Key)
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(Key)
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(CryptoKey, mGlobal, mAlgorithm)
NS_IMPL_CYCLE_COLLECTING_ADDREF(CryptoKey)
NS_IMPL_CYCLE_COLLECTING_RELEASE(CryptoKey)
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(CryptoKey)
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
NS_INTERFACE_MAP_ENTRY(nsISupports)
NS_INTERFACE_MAP_END
nsresult
StringToUsage(const nsString& aUsage, Key::KeyUsage& aUsageOut)
StringToUsage(const nsString& aUsage, CryptoKey::KeyUsage& aUsageOut)
{
if (aUsage.EqualsLiteral(WEBCRYPTO_KEY_USAGE_ENCRYPT)) {
aUsageOut = Key::ENCRYPT;
aUsageOut = CryptoKey::ENCRYPT;
} else if (aUsage.EqualsLiteral(WEBCRYPTO_KEY_USAGE_DECRYPT)) {
aUsageOut = Key::DECRYPT;
aUsageOut = CryptoKey::DECRYPT;
} else if (aUsage.EqualsLiteral(WEBCRYPTO_KEY_USAGE_SIGN)) {
aUsageOut = Key::SIGN;
aUsageOut = CryptoKey::SIGN;
} else if (aUsage.EqualsLiteral(WEBCRYPTO_KEY_USAGE_VERIFY)) {
aUsageOut = Key::VERIFY;
aUsageOut = CryptoKey::VERIFY;
} else if (aUsage.EqualsLiteral(WEBCRYPTO_KEY_USAGE_DERIVEKEY)) {
aUsageOut = Key::DERIVEKEY;
aUsageOut = CryptoKey::DERIVEKEY;
} else if (aUsage.EqualsLiteral(WEBCRYPTO_KEY_USAGE_DERIVEBITS)) {
aUsageOut = Key::DERIVEBITS;
aUsageOut = CryptoKey::DERIVEBITS;
} else if (aUsage.EqualsLiteral(WEBCRYPTO_KEY_USAGE_WRAPKEY)) {
aUsageOut = Key::WRAPKEY;
aUsageOut = CryptoKey::WRAPKEY;
} else if (aUsage.EqualsLiteral(WEBCRYPTO_KEY_USAGE_UNWRAPKEY)) {
aUsageOut = Key::UNWRAPKEY;
aUsageOut = CryptoKey::UNWRAPKEY;
} else {
return NS_ERROR_DOM_SYNTAX_ERR;
}
return NS_OK;
}
Key::Key(nsIGlobalObject* aGlobal)
CryptoKey::CryptoKey(nsIGlobalObject* aGlobal)
: mGlobal(aGlobal)
, mAttributes(0)
, mSymKey()
@ -57,7 +57,7 @@ Key::Key(nsIGlobalObject* aGlobal)
SetIsDOMBinding();
}
Key::~Key()
CryptoKey::~CryptoKey()
{
nsNSSShutDownPreventionLock locker;
if (isAlreadyShutDown()) {
@ -68,13 +68,13 @@ Key::~Key()
}
JSObject*
Key::WrapObject(JSContext* aCx)
CryptoKey::WrapObject(JSContext* aCx)
{
return KeyBinding::Wrap(aCx, this);
return CryptoKeyBinding::Wrap(aCx, this);
}
void
Key::GetType(nsString& aRetVal) const
CryptoKey::GetType(nsString& aRetVal) const
{
uint32_t type = mAttributes & TYPE_MASK;
switch (type) {
@ -85,19 +85,19 @@ Key::GetType(nsString& aRetVal) const
}
bool
Key::Extractable() const
CryptoKey::Extractable() const
{
return (mAttributes & EXTRACTABLE);
}
KeyAlgorithm*
Key::Algorithm() const
CryptoKey::Algorithm() const
{
return mAlgorithm;
}
void
Key::GetUsages(nsTArray<nsString>& aRetVal) const
CryptoKey::GetUsages(nsTArray<nsString>& aRetVal) const
{
if (mAttributes & ENCRYPT) {
aRetVal.AppendElement(NS_LITERAL_STRING(WEBCRYPTO_KEY_USAGE_ENCRYPT));
@ -125,14 +125,14 @@ Key::GetUsages(nsTArray<nsString>& aRetVal) const
}
}
Key::KeyType
Key::GetKeyType() const
CryptoKey::KeyType
CryptoKey::GetKeyType() const
{
return static_cast<Key::KeyType>(mAttributes & TYPE_MASK);
return static_cast<CryptoKey::KeyType>(mAttributes & TYPE_MASK);
}
nsresult
Key::SetType(const nsString& aType)
CryptoKey::SetType(const nsString& aType)
{
mAttributes &= CLEAR_TYPE;
if (aType.EqualsLiteral(WEBCRYPTO_KEY_TYPE_SECRET)) {
@ -150,14 +150,14 @@ Key::SetType(const nsString& aType)
}
void
Key::SetType(Key::KeyType aType)
CryptoKey::SetType(CryptoKey::KeyType aType)
{
mAttributes &= CLEAR_TYPE;
mAttributes |= aType;
}
void
Key::SetExtractable(bool aExtractable)
CryptoKey::SetExtractable(bool aExtractable)
{
mAttributes &= CLEAR_EXTRACTABLE;
if (aExtractable) {
@ -166,25 +166,25 @@ Key::SetExtractable(bool aExtractable)
}
void
Key::SetAlgorithm(KeyAlgorithm* aAlgorithm)
CryptoKey::SetAlgorithm(KeyAlgorithm* aAlgorithm)
{
mAlgorithm = aAlgorithm;
}
void
Key::ClearUsages()
CryptoKey::ClearUsages()
{
mAttributes &= CLEAR_USAGES;
}
nsresult
Key::AddUsage(const nsString& aUsage)
CryptoKey::AddUsage(const nsString& aUsage)
{
return AddUsageIntersecting(aUsage, USAGES_MASK);
}
nsresult
Key::AddUsageIntersecting(const nsString& aUsage, uint32_t aUsageMask)
CryptoKey::AddUsageIntersecting(const nsString& aUsage, uint32_t aUsageMask)
{
KeyUsage usage;
if (NS_FAILED(StringToUsage(aUsage, usage))) {
@ -200,30 +200,30 @@ Key::AddUsageIntersecting(const nsString& aUsage, uint32_t aUsageMask)
}
void
Key::AddUsage(Key::KeyUsage aUsage)
CryptoKey::AddUsage(CryptoKey::KeyUsage aUsage)
{
mAttributes |= aUsage;
}
bool
Key::HasUsage(Key::KeyUsage aUsage)
CryptoKey::HasUsage(CryptoKey::KeyUsage aUsage)
{
return !!(mAttributes & aUsage);
}
bool
Key::HasUsageOtherThan(uint32_t aUsages)
CryptoKey::HasUsageOtherThan(uint32_t aUsages)
{
return !!(mAttributes & USAGES_MASK & ~aUsages);
}
void Key::SetSymKey(const CryptoBuffer& aSymKey)
void CryptoKey::SetSymKey(const CryptoBuffer& aSymKey)
{
mSymKey = aSymKey;
}
void
Key::SetPrivateKey(SECKEYPrivateKey* aPrivateKey)
CryptoKey::SetPrivateKey(SECKEYPrivateKey* aPrivateKey)
{
nsNSSShutDownPreventionLock locker;
if (!aPrivateKey || isAlreadyShutDown()) {
@ -234,7 +234,7 @@ Key::SetPrivateKey(SECKEYPrivateKey* aPrivateKey)
}
void
Key::SetPublicKey(SECKEYPublicKey* aPublicKey)
CryptoKey::SetPublicKey(SECKEYPublicKey* aPublicKey)
{
nsNSSShutDownPreventionLock locker;
if (!aPublicKey || isAlreadyShutDown()) {
@ -245,13 +245,13 @@ Key::SetPublicKey(SECKEYPublicKey* aPublicKey)
}
const CryptoBuffer&
Key::GetSymKey() const
CryptoKey::GetSymKey() const
{
return mSymKey;
}
SECKEYPrivateKey*
Key::GetPrivateKey() const
CryptoKey::GetPrivateKey() const
{
nsNSSShutDownPreventionLock locker;
if (!mPrivateKey || isAlreadyShutDown()) {
@ -261,7 +261,7 @@ Key::GetPrivateKey() const
}
SECKEYPublicKey*
Key::GetPublicKey() const
CryptoKey::GetPublicKey() const
{
nsNSSShutDownPreventionLock locker;
if (!mPublicKey || isAlreadyShutDown()) {
@ -270,12 +270,12 @@ Key::GetPublicKey() const
return SECKEY_CopyPublicKey(mPublicKey.get());
}
void Key::virtualDestroyNSSReference()
void CryptoKey::virtualDestroyNSSReference()
{
destructorSafeDestroyNSSReference();
}
void Key::destructorSafeDestroyNSSReference()
void CryptoKey::destructorSafeDestroyNSSReference()
{
mPrivateKey.dispose();
mPublicKey.dispose();
@ -285,7 +285,7 @@ void Key::destructorSafeDestroyNSSReference()
// Serialization and deserialization convenience methods
SECKEYPrivateKey*
Key::PrivateKeyFromPkcs8(CryptoBuffer& aKeyData,
CryptoKey::PrivateKeyFromPkcs8(CryptoBuffer& aKeyData,
const nsNSSShutDownPreventionLock& /*proofOfLock*/)
{
SECKEYPrivateKey* privKey;
@ -309,7 +309,7 @@ Key::PrivateKeyFromPkcs8(CryptoBuffer& aKeyData,
}
SECKEYPublicKey*
Key::PublicKeyFromSpki(CryptoBuffer& aKeyData,
CryptoKey::PublicKeyFromSpki(CryptoBuffer& aKeyData,
const nsNSSShutDownPreventionLock& /*proofOfLock*/)
{
ScopedSECItem spkiItem(aKeyData.ToSECItem());
@ -326,7 +326,7 @@ Key::PublicKeyFromSpki(CryptoBuffer& aKeyData,
}
nsresult
Key::PrivateKeyToPkcs8(SECKEYPrivateKey* aPrivKey,
CryptoKey::PrivateKeyToPkcs8(SECKEYPrivateKey* aPrivKey,
CryptoBuffer& aRetVal,
const nsNSSShutDownPreventionLock& /*proofOfLock*/)
{
@ -339,7 +339,7 @@ Key::PrivateKeyToPkcs8(SECKEYPrivateKey* aPrivKey,
}
nsresult
Key::PublicKeyToSpki(SECKEYPublicKey* aPubKey,
CryptoKey::PublicKeyToSpki(SECKEYPublicKey* aPubKey,
CryptoBuffer& aRetVal,
const nsNSSShutDownPreventionLock& /*proofOfLock*/)
{
@ -353,7 +353,7 @@ Key::PublicKeyToSpki(SECKEYPublicKey* aPubKey,
}
bool
Key::WriteStructuredClone(JSStructuredCloneWriter* aWriter) const
CryptoKey::WriteStructuredClone(JSStructuredCloneWriter* aWriter) const
{
nsNSSShutDownPreventionLock locker;
if (isAlreadyShutDown()) {
@ -369,11 +369,11 @@ Key::WriteStructuredClone(JSStructuredCloneWriter* aWriter) const
CryptoBuffer priv, pub;
if (mPrivateKey) {
Key::PrivateKeyToPkcs8(mPrivateKey, priv, locker);
CryptoKey::PrivateKeyToPkcs8(mPrivateKey, priv, locker);
}
if (mPublicKey) {
Key::PublicKeyToSpki(mPublicKey, pub, locker);
CryptoKey::PublicKeyToSpki(mPublicKey, pub, locker);
}
return JS_WriteUint32Pair(aWriter, mAttributes, 0) &&
@ -384,7 +384,7 @@ Key::WriteStructuredClone(JSStructuredCloneWriter* aWriter) const
}
bool
Key::ReadStructuredClone(JSStructuredCloneReader* aReader)
CryptoKey::ReadStructuredClone(JSStructuredCloneReader* aReader)
{
nsNSSShutDownPreventionLock locker;
if (isAlreadyShutDown()) {
@ -408,10 +408,10 @@ Key::ReadStructuredClone(JSStructuredCloneReader* aReader)
mSymKey = sym;
}
if (priv.Length() > 0) {
mPrivateKey = Key::PrivateKeyFromPkcs8(priv, locker);
mPrivateKey = CryptoKey::PrivateKeyFromPkcs8(priv, locker);
}
if (pub.Length() > 0) {
mPublicKey = Key::PublicKeyFromSpki(pub, locker);
mPublicKey = CryptoKey::PublicKeyFromSpki(pub, locker);
}
mAlgorithm = algorithm;

View File

@ -4,8 +4,8 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef mozilla_dom_Key_h
#define mozilla_dom_Key_h
#ifndef mozilla_dom_CryptoKey_h
#define mozilla_dom_CryptoKey_h
#include "nsCycleCollectionParticipant.h"
#include "nsWrapperCache.h"
@ -49,17 +49,17 @@ In the order of a hex value for a uint32_t
Thus, internally, a key has the following fields:
* uint32_t - flags for extractable, usage, type
* KeyAlgorithm - the algorithm (which must serialize/deserialize itself)
* The actual keys (which the Key must serialize)
* The actual keys (which the CryptoKey must serialize)
*/
class Key MOZ_FINAL : public nsISupports,
public nsWrapperCache,
public nsNSSShutDownObject
class CryptoKey MOZ_FINAL : public nsISupports,
public nsWrapperCache,
public nsNSSShutDownObject
{
public:
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(Key)
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(CryptoKey)
static const uint32_t CLEAR_EXTRACTABLE = 0xFFFFFFE;
static const uint32_t EXTRACTABLE = 0x00000001;
@ -86,7 +86,7 @@ public:
UNWRAPKEY = 0x00800000
};
Key(nsIGlobalObject* aWindow);
CryptoKey(nsIGlobalObject* aWindow);
nsIGlobalObject* GetParentObject() const
{
@ -154,7 +154,7 @@ public:
bool ReadStructuredClone(JSStructuredCloneReader* aReader);
private:
~Key();
~CryptoKey();
nsRefPtr<nsIGlobalObject> mGlobal;
uint32_t mAttributes; // see above
@ -169,4 +169,4 @@ private:
} // namespace dom
} // namespace mozilla
#endif // mozilla_dom_Key_h
#endif // mozilla_dom_CryptoKey_h

View File

@ -4,7 +4,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "mozilla/dom/KeyPair.h"
#include "mozilla/dom/CryptoKeyPair.h"
#include "mozilla/dom/SubtleCryptoBinding.h"
#include "nsContentUtils.h"
@ -12,18 +12,18 @@ namespace mozilla {
namespace dom {
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(KeyPair, mGlobal, mPublicKey, mPrivateKey)
NS_IMPL_CYCLE_COLLECTING_ADDREF(KeyPair)
NS_IMPL_CYCLE_COLLECTING_RELEASE(KeyPair)
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(KeyPair)
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(CryptoKeyPair, mGlobal, mPublicKey, mPrivateKey)
NS_IMPL_CYCLE_COLLECTING_ADDREF(CryptoKeyPair)
NS_IMPL_CYCLE_COLLECTING_RELEASE(CryptoKeyPair)
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(CryptoKeyPair)
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
NS_INTERFACE_MAP_ENTRY(nsISupports)
NS_INTERFACE_MAP_END
JSObject*
KeyPair::WrapObject(JSContext* aCx)
CryptoKeyPair::WrapObject(JSContext* aCx)
{
return KeyPairBinding::Wrap(aCx, this);
return CryptoKeyPairBinding::Wrap(aCx, this);
}

View File

@ -4,30 +4,30 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef mozilla_dom_KeyPair_h
#define mozilla_dom_KeyPair_h
#ifndef mozilla_dom_CryptoKeyPair_h
#define mozilla_dom_CryptoKeyPair_h
#include "nsCycleCollectionParticipant.h"
#include "nsWrapperCache.h"
#include "nsIGlobalObject.h"
#include "mozilla/dom/Key.h"
#include "mozilla/dom/CryptoKey.h"
#include "js/TypeDecls.h"
namespace mozilla {
namespace dom {
class KeyPair MOZ_FINAL : public nsISupports,
public nsWrapperCache
class CryptoKeyPair MOZ_FINAL : public nsISupports,
public nsWrapperCache
{
public:
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(KeyPair)
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(CryptoKeyPair)
public:
KeyPair(nsIGlobalObject* aGlobal)
CryptoKeyPair(nsIGlobalObject* aGlobal)
: mGlobal(aGlobal)
, mPublicKey(new Key(aGlobal))
, mPrivateKey(new Key(aGlobal))
, mPublicKey(new CryptoKey(aGlobal))
, mPrivateKey(new CryptoKey(aGlobal))
{
SetIsDOMBinding();
}
@ -39,25 +39,25 @@ public:
virtual JSObject* WrapObject(JSContext* aCx) MOZ_OVERRIDE;
Key* PublicKey() const
CryptoKey* PublicKey() const
{
return mPublicKey;
}
Key* PrivateKey() const
CryptoKey* PrivateKey() const
{
return mPrivateKey;
}
private:
~KeyPair() {}
~CryptoKeyPair() {}
nsRefPtr<nsIGlobalObject> mGlobal;
nsRefPtr<Key> mPublicKey;
nsRefPtr<Key> mPrivateKey;
nsRefPtr<CryptoKey> mPublicKey;
nsRefPtr<CryptoKey> mPrivateKey;
};
} // namespace dom
} // namespace mozilla
#endif // mozilla_dom_KeyPair_h
#endif // mozilla_dom_CryptoKeyPair_h

View File

@ -18,7 +18,7 @@
namespace mozilla {
namespace dom {
class Key;
class CryptoKey;
class KeyAlgorithm;
enum KeyAlgorithmStructuredCloneTags {

View File

@ -11,9 +11,9 @@
#include "mozilla/dom/WebCryptoTask.h"
#include "mozilla/dom/TypedArray.h"
#include "mozilla/dom/Key.h"
#include "mozilla/dom/CryptoKey.h"
#include "mozilla/dom/KeyAlgorithm.h"
#include "mozilla/dom/KeyPair.h"
#include "mozilla/dom/CryptoKeyPair.h"
#include "mozilla/dom/AesKeyAlgorithm.h"
#include "mozilla/dom/HmacKeyAlgorithm.h"
#include "mozilla/dom/RsaKeyAlgorithm.h"
@ -231,7 +231,7 @@ class AesTask : public ReturnArrayBufferViewTask
{
public:
AesTask(JSContext* aCx, const ObjectOrString& aAlgorithm,
mozilla::dom::Key& aKey, const CryptoOperationData& aData,
mozilla::dom::CryptoKey& aKey, const CryptoOperationData& aData,
bool aEncrypt)
: mSymKey(aKey.GetSymKey())
, mEncrypt(aEncrypt)
@ -408,7 +408,7 @@ class RsaesPkcs1Task : public ReturnArrayBufferViewTask
{
public:
RsaesPkcs1Task(JSContext* aCx, const ObjectOrString& aAlgorithm,
mozilla::dom::Key& aKey, const CryptoOperationData& aData,
mozilla::dom::CryptoKey& aKey, const CryptoOperationData& aData,
bool aEncrypt)
: mPrivKey(aKey.GetPrivateKey())
, mPubKey(aKey.GetPublicKey())
@ -481,7 +481,7 @@ class HmacTask : public WebCryptoTask
{
public:
HmacTask(JSContext* aCx, const ObjectOrString& aAlgorithm,
mozilla::dom::Key& aKey,
mozilla::dom::CryptoKey& aKey,
const CryptoOperationData& aSignature,
const CryptoOperationData& aData,
bool aSign)
@ -584,7 +584,7 @@ class RsassaPkcs1Task : public WebCryptoTask
{
public:
RsassaPkcs1Task(JSContext* aCx, const ObjectOrString& aAlgorithm,
mozilla::dom::Key& aKey,
mozilla::dom::CryptoKey& aKey,
const CryptoOperationData& aSignature,
const CryptoOperationData& aData,
bool aSign)
@ -775,7 +775,7 @@ public:
}
// This stuff pretty much always happens, so we'll do it here
mKey = new Key(global);
mKey = new CryptoKey(global);
mKey->SetExtractable(aExtractable);
mKey->ClearUsages();
for (uint32_t i = 0; i < aKeyUsages.Length(); ++i) {
@ -793,7 +793,7 @@ public:
}
protected:
nsRefPtr<Key> mKey;
nsRefPtr<CryptoKey> mKey;
nsString mAlgName;
private:
@ -867,7 +867,7 @@ public:
if (mAlgName.EqualsLiteral(WEBCRYPTO_ALG_AES_CBC) ||
mAlgName.EqualsLiteral(WEBCRYPTO_ALG_AES_CTR) ||
mAlgName.EqualsLiteral(WEBCRYPTO_ALG_AES_GCM)) {
if (mKey->HasUsageOtherThan(Key::ENCRYPT | Key::DECRYPT)) {
if (mKey->HasUsageOtherThan(CryptoKey::ENCRYPT | CryptoKey::DECRYPT)) {
return NS_ERROR_DOM_DATA_ERR;
}
@ -876,7 +876,7 @@ public:
}
algorithm = new AesKeyAlgorithm(global, mAlgName, length);
} else if (mAlgName.EqualsLiteral(WEBCRYPTO_ALG_HMAC)) {
if (mKey->HasUsageOtherThan(Key::SIGN | Key::VERIFY)) {
if (mKey->HasUsageOtherThan(CryptoKey::SIGN | CryptoKey::VERIFY)) {
return NS_ERROR_DOM_DATA_ERR;
}
@ -890,7 +890,7 @@ public:
mKey->SetAlgorithm(algorithm);
mKey->SetSymKey(mKeyData);
mKey->SetType(Key::SECRET);
mKey->SetType(CryptoKey::SECRET);
mEarlyComplete = true;
return NS_OK;
}
@ -957,19 +957,19 @@ private:
// Import the key data itself
ScopedSECKEYPublicKey pubKey;
if (mFormat.EqualsLiteral(WEBCRYPTO_KEY_FORMAT_PKCS8)) {
ScopedSECKEYPrivateKey privKey(Key::PrivateKeyFromPkcs8(mKeyData, locker));
ScopedSECKEYPrivateKey privKey(CryptoKey::PrivateKeyFromPkcs8(mKeyData, locker));
if (!privKey.get()) {
return NS_ERROR_DOM_DATA_ERR;
}
mKey->SetPrivateKey(privKey.get());
mKey->SetType(Key::PRIVATE);
mKey->SetType(CryptoKey::PRIVATE);
pubKey = SECKEY_ConvertToPublicKey(privKey.get());
if (!pubKey) {
return NS_ERROR_DOM_UNKNOWN_ERR;
}
} else if (mFormat.EqualsLiteral(WEBCRYPTO_KEY_FORMAT_SPKI)) {
pubKey = Key::PublicKeyFromSpki(mKeyData, locker);
pubKey = CryptoKey::PublicKeyFromSpki(mKeyData, locker);
if (!pubKey.get()) {
return NS_ERROR_DOM_DATA_ERR;
}
@ -979,7 +979,7 @@ private:
}
mKey->SetPublicKey(pubKey.get());
mKey->SetType(Key::PUBLIC);
mKey->SetType(CryptoKey::PUBLIC);
} else if (mFormat.EqualsLiteral(WEBCRYPTO_KEY_FORMAT_JWK)) {
return NS_ERROR_DOM_NOT_SUPPORTED_ERR;
} else {
@ -999,19 +999,19 @@ private:
// Construct an appropriate KeyAlgorithm
nsIGlobalObject* global = mKey->GetParentObject();
if (mAlgName.EqualsLiteral(WEBCRYPTO_ALG_RSAES_PKCS1)) {
if ((mKey->GetKeyType() == Key::PUBLIC &&
mKey->HasUsageOtherThan(Key::ENCRYPT)) ||
(mKey->GetKeyType() == Key::PRIVATE &&
mKey->HasUsageOtherThan(Key::DECRYPT))) {
if ((mKey->GetKeyType() == CryptoKey::PUBLIC &&
mKey->HasUsageOtherThan(CryptoKey::ENCRYPT)) ||
(mKey->GetKeyType() == CryptoKey::PRIVATE &&
mKey->HasUsageOtherThan(CryptoKey::DECRYPT))) {
return NS_ERROR_DOM_DATA_ERR;
}
mKey->SetAlgorithm(new RsaKeyAlgorithm(global, mAlgName, mModulusLength, mPublicExponent));
} else if (mAlgName.EqualsLiteral(WEBCRYPTO_ALG_RSASSA_PKCS1)) {
if ((mKey->GetKeyType() == Key::PUBLIC &&
mKey->HasUsageOtherThan(Key::VERIFY)) ||
(mKey->GetKeyType() == Key::PRIVATE &&
mKey->HasUsageOtherThan(Key::SIGN))) {
if ((mKey->GetKeyType() == CryptoKey::PUBLIC &&
mKey->HasUsageOtherThan(CryptoKey::VERIFY)) ||
(mKey->GetKeyType() == CryptoKey::PRIVATE &&
mKey->HasUsageOtherThan(CryptoKey::SIGN))) {
return NS_ERROR_DOM_DATA_ERR;
}
@ -1035,7 +1035,7 @@ private:
class UnifiedExportKeyTask : public ReturnArrayBufferViewTask
{
public:
UnifiedExportKeyTask(const nsAString& aFormat, Key& aKey)
UnifiedExportKeyTask(const nsAString& aFormat, CryptoKey& aKey)
: mFormat(aFormat)
, mSymKey(aKey.GetSymKey())
, mPrivateKey(aKey.GetPrivateKey())
@ -1078,7 +1078,7 @@ private:
switch (mPrivateKey->keyType) {
case rsaKey:
Key::PrivateKeyToPkcs8(mPrivateKey.get(), mResult, locker);
CryptoKey::PrivateKeyToPkcs8(mPrivateKey.get(), mResult, locker);
return NS_OK;
default:
return NS_ERROR_DOM_NOT_SUPPORTED_ERR;
@ -1088,7 +1088,7 @@ private:
return NS_ERROR_DOM_NOT_SUPPORTED_ERR;
}
return Key::PublicKeyToSpki(mPublicKey.get(), mResult, locker);
return CryptoKey::PublicKeyToSpki(mPublicKey.get(), mResult, locker);
} else if (mFormat.EqualsLiteral(WEBCRYPTO_KEY_FORMAT_JWK)) {
return NS_ERROR_DOM_NOT_SUPPORTED_ERR;
}
@ -1111,9 +1111,9 @@ public:
}
// Create an empty key and set easy attributes
mKey = new Key(global);
mKey = new CryptoKey(global);
mKey->SetExtractable(aExtractable);
mKey->SetType(Key::SECRET);
mKey->SetType(CryptoKey::SECRET);
// Extract algorithm name
nsString algName;
@ -1142,7 +1142,7 @@ public:
return;
}
algorithm = new AesKeyAlgorithm(global, algName, mLength);
allowedUsages = Key::ENCRYPT | Key::DECRYPT;
allowedUsages = CryptoKey::ENCRYPT | CryptoKey::DECRYPT;
} else if (algName.EqualsLiteral(WEBCRYPTO_ALG_HMAC)) {
RootedDictionary<HmacKeyGenParams> params(aCx);
mEarlyRv = Coerce(aCx, params, aAlgorithm);
@ -1189,7 +1189,7 @@ public:
}
algorithm = new HmacKeyAlgorithm(global, algName, mLength, hashName);
allowedUsages = Key::SIGN | Key::VERIFY;
allowedUsages = CryptoKey::SIGN | CryptoKey::VERIFY;
} else {
mEarlyRv = NS_ERROR_DOM_NOT_SUPPORTED_ERR;
return;
@ -1211,7 +1211,7 @@ public:
}
private:
nsRefPtr<Key> mKey;
nsRefPtr<CryptoKey> mKey;
size_t mLength;
CK_MECHANISM_TYPE mMechanism;
CryptoBuffer mKeyData;
@ -1263,7 +1263,7 @@ public:
}
// Create an empty key and set easy attributes
mKeyPair = new KeyPair(global);
mKeyPair = new CryptoKeyPair(global);
// Extract algorithm name
nsString algName;
@ -1312,8 +1312,8 @@ public:
return;
}
privateAllowedUsages = Key::SIGN;
publicAllowedUsages = Key::VERIFY;
privateAllowedUsages = CryptoKey::SIGN;
publicAllowedUsages = CryptoKey::VERIFY;
} else if (algName.EqualsLiteral(WEBCRYPTO_ALG_RSAES_PKCS1)) {
RootedDictionary<RsaKeyGenParams> params(aCx);
mEarlyRv = Coerce(aCx, params, aAlgorithm);
@ -1343,18 +1343,18 @@ public:
return;
}
privateAllowedUsages = Key::DECRYPT | Key::UNWRAPKEY;
publicAllowedUsages = Key::ENCRYPT | Key::WRAPKEY;
privateAllowedUsages = CryptoKey::DECRYPT | CryptoKey::UNWRAPKEY;
publicAllowedUsages = CryptoKey::ENCRYPT | CryptoKey::WRAPKEY;
} else {
mEarlyRv = NS_ERROR_DOM_NOT_SUPPORTED_ERR;
return;
}
mKeyPair->PrivateKey()->SetExtractable(aExtractable);
mKeyPair->PrivateKey()->SetType(Key::PRIVATE);
mKeyPair->PrivateKey()->SetType(CryptoKey::PRIVATE);
mKeyPair->PublicKey()->SetExtractable(true);
mKeyPair->PublicKey()->SetType(Key::PUBLIC);
mKeyPair->PublicKey()->SetType(CryptoKey::PUBLIC);
mKeyPair->PrivateKey()->ClearUsages();
mKeyPair->PublicKey()->ClearUsages();
@ -1374,7 +1374,7 @@ public:
}
private:
nsRefPtr<KeyPair> mKeyPair;
nsRefPtr<CryptoKeyPair> mKeyPair;
CK_MECHANISM_TYPE mMechanism;
PK11RSAGenParams mRsaParams;
ScopedSECKEYPublicKey mPublicKey;
@ -1427,7 +1427,7 @@ private:
WebCryptoTask*
WebCryptoTask::EncryptDecryptTask(JSContext* aCx,
const ObjectOrString& aAlgorithm,
Key& aKey,
CryptoKey& aKey,
const CryptoOperationData& aData,
bool aEncrypt)
{
@ -1442,8 +1442,8 @@ WebCryptoTask::EncryptDecryptTask(JSContext* aCx,
}
// Ensure key is usable for this operation
if ((aEncrypt && !aKey.HasUsage(Key::ENCRYPT)) ||
(!aEncrypt && !aKey.HasUsage(Key::DECRYPT))) {
if ((aEncrypt && !aKey.HasUsage(CryptoKey::ENCRYPT)) ||
(!aEncrypt && !aKey.HasUsage(CryptoKey::DECRYPT))) {
return new FailureTask(NS_ERROR_DOM_INVALID_ACCESS_ERR);
}
@ -1461,7 +1461,7 @@ WebCryptoTask::EncryptDecryptTask(JSContext* aCx,
WebCryptoTask*
WebCryptoTask::SignVerifyTask(JSContext* aCx,
const ObjectOrString& aAlgorithm,
Key& aKey,
CryptoKey& aKey,
const CryptoOperationData& aSignature,
const CryptoOperationData& aData,
bool aSign)
@ -1477,8 +1477,8 @@ WebCryptoTask::SignVerifyTask(JSContext* aCx,
}
// Ensure key is usable for this operation
if ((aSign && !aKey.HasUsage(Key::SIGN)) ||
(!aSign && !aKey.HasUsage(Key::VERIFY))) {
if ((aSign && !aKey.HasUsage(CryptoKey::SIGN)) ||
(!aSign && !aKey.HasUsage(CryptoKey::VERIFY))) {
return new FailureTask(NS_ERROR_DOM_INVALID_ACCESS_ERR);
}
@ -1534,7 +1534,7 @@ WebCryptoTask::ImportKeyTask(JSContext* aCx,
WebCryptoTask*
WebCryptoTask::ExportKeyTask(const nsAString& aFormat,
Key& aKey)
CryptoKey& aKey)
{
Telemetry::Accumulate(Telemetry::WEBCRYPTO_METHOD, TM_EXPORTKEY);
@ -1576,7 +1576,7 @@ WebCryptoTask::GenerateKeyTask(JSContext* aCx,
WebCryptoTask*
WebCryptoTask::DeriveKeyTask(JSContext* aCx,
const ObjectOrString& aAlgorithm,
Key& aBaseKey,
CryptoKey& aBaseKey,
const ObjectOrString& aDerivedKeyType,
bool aExtractable,
const Sequence<nsString>& aKeyUsages)
@ -1588,7 +1588,7 @@ WebCryptoTask::DeriveKeyTask(JSContext* aCx,
WebCryptoTask*
WebCryptoTask::DeriveBitsTask(JSContext* aCx,
const ObjectOrString& aAlgorithm,
Key& aKey,
CryptoKey& aKey,
uint32_t aLength)
{
Telemetry::Accumulate(Telemetry::WEBCRYPTO_METHOD, TM_DERIVEBITS);

View File

@ -13,7 +13,7 @@
#include "mozilla/dom/Promise.h"
#include "mozilla/dom/DOMException.h"
#include "mozilla/dom/SubtleCryptoBinding.h"
#include "mozilla/dom/Key.h"
#include "mozilla/dom/CryptoKey.h"
namespace mozilla {
namespace dom {
@ -87,13 +87,13 @@ public:
protected:
static WebCryptoTask* EncryptDecryptTask(JSContext* aCx,
const ObjectOrString& aAlgorithm,
Key& aKey,
CryptoKey& aKey,
const CryptoOperationData& aData,
bool aEncrypt);
static WebCryptoTask* SignVerifyTask(JSContext* aCx,
const ObjectOrString& aAlgorithm,
Key& aKey,
CryptoKey& aKey,
const CryptoOperationData& aSignature,
const CryptoOperationData& aData,
bool aSign);
@ -101,7 +101,7 @@ protected:
public:
static WebCryptoTask* EncryptTask(JSContext* aCx,
const ObjectOrString& aAlgorithm,
Key& aKey,
CryptoKey& aKey,
const CryptoOperationData& aData)
{
return EncryptDecryptTask(aCx, aAlgorithm, aKey, aData, true);
@ -109,7 +109,7 @@ public:
static WebCryptoTask* DecryptTask(JSContext* aCx,
const ObjectOrString& aAlgorithm,
Key& aKey,
CryptoKey& aKey,
const CryptoOperationData& aData)
{
return EncryptDecryptTask(aCx, aAlgorithm, aKey, aData, false);
@ -117,7 +117,7 @@ public:
static WebCryptoTask* SignTask(JSContext* aCx,
const ObjectOrString& aAlgorithm,
Key& aKey,
CryptoKey& aKey,
const CryptoOperationData& aData)
{
CryptoOperationData dummy;
@ -127,7 +127,7 @@ public:
static WebCryptoTask* VerifyTask(JSContext* aCx,
const ObjectOrString& aAlgorithm,
Key& aKey,
CryptoKey& aKey,
const CryptoOperationData& aSignature,
const CryptoOperationData& aData)
{
@ -145,7 +145,7 @@ public:
bool aExtractable,
const Sequence<nsString>& aKeyUsages);
static WebCryptoTask* ExportKeyTask(const nsAString& aFormat,
Key& aKey);
CryptoKey& aKey);
static WebCryptoTask* GenerateKeyTask(JSContext* aCx,
const ObjectOrString& aAlgorithm,
bool aExtractable,
@ -153,13 +153,13 @@ public:
static WebCryptoTask* DeriveKeyTask(JSContext* aCx,
const ObjectOrString& aAlgorithm,
Key& aBaseKey,
CryptoKey& aBaseKey,
const ObjectOrString& aDerivedKeyType,
bool extractable,
const Sequence<nsString>& aKeyUsages);
static WebCryptoTask* DeriveBitsTask(JSContext* aCx,
const ObjectOrString& aAlgorithm,
Key& aKey,
CryptoKey& aKey,
uint32_t aLength);
protected:

View File

@ -9,10 +9,10 @@ TEST_DIRS += ['test']
EXPORTS.mozilla.dom += [
'AesKeyAlgorithm.h',
'CryptoBuffer.h',
'CryptoKey.h',
'CryptoKeyPair.h',
'HmacKeyAlgorithm.h',
'Key.h',
'KeyAlgorithm.h',
'KeyPair.h',
'RsaHashedKeyAlgorithm.h',
'RsaKeyAlgorithm.h',
'WebCryptoCommon.h',
@ -22,10 +22,10 @@ EXPORTS.mozilla.dom += [
UNIFIED_SOURCES += [
'AesKeyAlgorithm.cpp',
'CryptoBuffer.cpp',
'CryptoKey.cpp',
'CryptoKeyPair.cpp',
'HmacKeyAlgorithm.cpp',
'Key.cpp',
'KeyAlgorithm.cpp',
'KeyPair.cpp',
'RsaHashedKeyAlgorithm.cpp',
'RsaKeyAlgorithm.cpp',
'WebCryptoTask.cpp',

View File

@ -102,7 +102,7 @@ dictionary EcKeyGenParams : Algorithm {
/***** The Main API *****/
[Pref="dom.webcrypto.enabled"]
interface Key {
interface CryptoKey {
readonly attribute KeyType type;
readonly attribute boolean extractable;
readonly attribute KeyAlgorithm algorithm;
@ -110,9 +110,9 @@ interface Key {
};
[Pref="dom.webcrypto.enabled"]
interface KeyPair {
readonly attribute Key publicKey;
readonly attribute Key privateKey;
interface CryptoKeyPair {
readonly attribute CryptoKey publicKey;
readonly attribute CryptoKey privateKey;
};
typedef DOMString KeyFormat;
@ -123,16 +123,16 @@ typedef (object or DOMString) AlgorithmIdentifier;
[Pref="dom.webcrypto.enabled"]
interface SubtleCrypto {
Promise encrypt(AlgorithmIdentifier algorithm,
Key key,
CryptoKey key,
CryptoOperationData data);
Promise decrypt(AlgorithmIdentifier algorithm,
Key key,
CryptoKey key,
CryptoOperationData data);
Promise sign(AlgorithmIdentifier algorithm,
Key key,
CryptoKey key,
CryptoOperationData data);
Promise verify(AlgorithmIdentifier algorithm,
Key key,
CryptoKey key,
CryptoOperationData signature,
CryptoOperationData data);
Promise digest(AlgorithmIdentifier algorithm,
@ -142,12 +142,12 @@ interface SubtleCrypto {
boolean extractable,
sequence<KeyUsage> keyUsages );
Promise deriveKey(AlgorithmIdentifier algorithm,
Key baseKey,
CryptoKey baseKey,
AlgorithmIdentifier derivedKeyType,
boolean extractable,
sequence<KeyUsage> keyUsages );
Promise deriveBits(AlgorithmIdentifier algorithm,
Key baseKey,
CryptoKey baseKey,
unsigned long length);
Promise importKey(KeyFormat format,
@ -155,6 +155,6 @@ interface SubtleCrypto {
AlgorithmIdentifier algorithm,
boolean extractable,
sequence<KeyUsage> keyUsages );
Promise exportKey(KeyFormat format, Key key);
Promise exportKey(KeyFormat format, CryptoKey key);
};