Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(123)

Unified Diff: public/platform/WebCryptoAlgorithmParams.h

Issue 179353002: [webcrypto] Add the KeyAlgorithm interface. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: rebase yet again (another conflict) Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « public/platform/WebCryptoAlgorithm.h ('k') | public/platform/WebCryptoKey.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: public/platform/WebCryptoAlgorithmParams.h
diff --git a/public/platform/WebCryptoAlgorithmParams.h b/public/platform/WebCryptoAlgorithmParams.h
index aaed0847aa4713c322de61a44451157b67448ba6..f6fe2ee0b7bf369d2f16d562052bf0e4f0604277 100644
--- a/public/platform/WebCryptoAlgorithmParams.h
+++ b/public/platform/WebCryptoAlgorithmParams.h
@@ -51,42 +51,51 @@ namespace blink {
class WebCryptoAlgorithmParams {
public:
- explicit WebCryptoAlgorithmParams(WebCryptoAlgorithmParamsType type)
- : m_type(type)
+ WebCryptoAlgorithmParams() { }
+ virtual ~WebCryptoAlgorithmParams() { }
+ virtual WebCryptoAlgorithmParamsType type() const = 0;
+};
+
+class WebCryptoAesCbcParams : public WebCryptoAlgorithmParams {
+public:
+ WebCryptoAesCbcParams(const unsigned char* iv, unsigned ivSize)
+ : m_iv(iv, ivSize)
{
}
- virtual ~WebCryptoAlgorithmParams() { }
+ virtual WebCryptoAlgorithmParamsType type() const { return WebCryptoAlgorithmParamsTypeAesCbcParams; }
- WebCryptoAlgorithmParamsType type() const { return m_type; }
+ const WebVector<unsigned char>& iv() const { return m_iv; }
private:
- const WebCryptoAlgorithmParamsType m_type;
+ const WebVector<unsigned char> m_iv;
};
-class WebCryptoAesCbcParams : public WebCryptoAlgorithmParams {
+class WebCryptoAlgorithmParamsWithHash : public WebCryptoAlgorithmParams {
public:
- WebCryptoAesCbcParams(const unsigned char* iv, unsigned ivSize)
- : WebCryptoAlgorithmParams(WebCryptoAlgorithmParamsTypeAesCbcParams)
- , m_iv(iv, ivSize)
+ explicit WebCryptoAlgorithmParamsWithHash(const WebCryptoAlgorithm& hash)
+ : m_hash(hash)
{
+ BLINK_ASSERT(!hash.isNull());
}
- const WebVector<unsigned char>& iv() const { return m_iv; }
+ const WebCryptoAlgorithm& hash() const { return m_hash; }
private:
- const WebVector<unsigned char> m_iv;
+ const WebCryptoAlgorithm m_hash;
};
class WebCryptoAesCtrParams : public WebCryptoAlgorithmParams {
public:
WebCryptoAesCtrParams(unsigned char lengthBits, const unsigned char* counter, unsigned counterSize)
- : WebCryptoAlgorithmParams(WebCryptoAlgorithmParamsTypeAesCtrParams)
+ : WebCryptoAlgorithmParams()
, m_counter(counter, counterSize)
, m_lengthBits(lengthBits)
{
}
+ virtual WebCryptoAlgorithmParamsType type() const { return WebCryptoAlgorithmParamsTypeAesCtrParams; }
+
const WebVector<unsigned char>& counter() const { return m_counter; }
unsigned char lengthBits() const { return m_lengthBits; }
@@ -98,80 +107,59 @@ private:
class WebCryptoAesKeyGenParams : public WebCryptoAlgorithmParams {
public:
explicit WebCryptoAesKeyGenParams(unsigned short lengthBits)
- : WebCryptoAlgorithmParams(WebCryptoAlgorithmParamsTypeAesKeyGenParams)
- , m_lengthBits(lengthBits)
+ : m_lengthBits(lengthBits)
{
}
+ virtual WebCryptoAlgorithmParamsType type() const { return WebCryptoAlgorithmParamsTypeAesKeyGenParams; }
+
unsigned short lengthBits() const { return m_lengthBits; }
private:
const unsigned short m_lengthBits;
};
-class WebCryptoHmacParams : public WebCryptoAlgorithmParams {
+class WebCryptoHmacImportParams : public WebCryptoAlgorithmParamsWithHash {
public:
- explicit WebCryptoHmacParams(const WebCryptoAlgorithm& hash)
- : WebCryptoAlgorithmParams(WebCryptoAlgorithmParamsTypeHmacParams)
- , m_hash(hash)
+ explicit WebCryptoHmacImportParams(const WebCryptoAlgorithm& hash)
+ : WebCryptoAlgorithmParamsWithHash(hash)
{
- BLINK_ASSERT(!hash.isNull());
}
- const WebCryptoAlgorithm& hash() const { return m_hash; }
-
-private:
- const WebCryptoAlgorithm m_hash;
+ virtual WebCryptoAlgorithmParamsType type() const { return WebCryptoAlgorithmParamsTypeHmacImportParams; }
};
-class WebCryptoHmacKeyParams : public WebCryptoAlgorithmParams {
+class WebCryptoHmacKeyGenParams : public WebCryptoAlgorithmParamsWithHash {
public:
- WebCryptoHmacKeyParams(const WebCryptoAlgorithm& hash, bool hasLengthBytes, unsigned lengthBytes)
- : WebCryptoAlgorithmParams(WebCryptoAlgorithmParamsTypeHmacKeyParams)
- , m_hash(hash)
+ WebCryptoHmacKeyGenParams(const WebCryptoAlgorithm& hash, bool hasLengthBytes, unsigned lengthBytes)
+ : WebCryptoAlgorithmParamsWithHash(hash)
, m_hasLengthBytes(hasLengthBytes)
, m_optionalLengthBytes(lengthBytes)
{
- BLINK_ASSERT(!hash.isNull());
BLINK_ASSERT(hasLengthBytes || !lengthBytes);
}
- const WebCryptoAlgorithm& hash() const { return m_hash; }
+ virtual WebCryptoAlgorithmParamsType type() const { return WebCryptoAlgorithmParamsTypeHmacKeyGenParams; }
bool hasLengthBytes() const { return m_hasLengthBytes; }
unsigned optionalLengthBytes() const { return m_optionalLengthBytes; }
private:
- const WebCryptoAlgorithm m_hash;
const bool m_hasLengthBytes;
const unsigned m_optionalLengthBytes;
};
-class WebCryptoRsaSsaParams : public WebCryptoAlgorithmParams {
-public:
- explicit WebCryptoRsaSsaParams(const WebCryptoAlgorithm& hash)
- : WebCryptoAlgorithmParams(WebCryptoAlgorithmParamsTypeRsaSsaParams)
- , m_hash(hash)
- {
- BLINK_ASSERT(!hash.isNull());
- }
-
- const WebCryptoAlgorithm& hash() const { return m_hash; }
-
-private:
- const WebCryptoAlgorithm m_hash;
-};
-
class WebCryptoRsaKeyGenParams : public WebCryptoAlgorithmParams {
public:
WebCryptoRsaKeyGenParams(unsigned modulusLengthBits, const unsigned char* publicExponent, unsigned publicExponentSize)
- : WebCryptoAlgorithmParams(WebCryptoAlgorithmParamsTypeRsaKeyGenParams)
- , m_modulusLengthBits(modulusLengthBits)
+ : m_modulusLengthBits(modulusLengthBits)
, m_publicExponent(publicExponent, publicExponentSize)
{
}
+ virtual WebCryptoAlgorithmParamsType type() const { return WebCryptoAlgorithmParamsTypeRsaKeyGenParams; }
+
unsigned modulusLengthBits() const { return m_modulusLengthBits; }
const WebVector<unsigned char>& publicExponent() const { return m_publicExponent; }
@@ -183,8 +171,7 @@ private:
class WebCryptoAesGcmParams : public WebCryptoAlgorithmParams {
public:
WebCryptoAesGcmParams(const unsigned char* iv, unsigned ivSize, bool hasAdditionalData, const unsigned char* additionalData, unsigned additionalDataSize, bool hasTagLengthBits, unsigned char tagLengthBits)
- : WebCryptoAlgorithmParams(WebCryptoAlgorithmParamsTypeAesGcmParams)
- , m_iv(iv, ivSize)
+ : m_iv(iv, ivSize)
, m_hasAdditionalData(hasAdditionalData)
, m_optionalAdditionalData(additionalData, additionalDataSize)
, m_hasTagLengthBits(hasTagLengthBits)
@@ -194,6 +181,8 @@ public:
BLINK_ASSERT(hasTagLengthBits || !tagLengthBits);
}
+ virtual WebCryptoAlgorithmParamsType type() const { return WebCryptoAlgorithmParamsTypeAesGcmParams; }
+
const WebVector<unsigned char>& iv() const { return m_iv; }
bool hasAdditionalData() const { return m_hasAdditionalData; }
@@ -210,25 +199,48 @@ private:
const unsigned char m_optionalTagLengthBits;
};
-class WebCryptoRsaOaepParams : public WebCryptoAlgorithmParams {
+class WebCryptoRsaHashedImportParams : public WebCryptoAlgorithmParamsWithHash {
+public:
+ explicit WebCryptoRsaHashedImportParams(const WebCryptoAlgorithm& hash)
+ : WebCryptoAlgorithmParamsWithHash(hash)
+ {
+ }
+
+ virtual WebCryptoAlgorithmParamsType type() const { return WebCryptoAlgorithmParamsTypeRsaHashedImportParams; }
+};
+
+class WebCryptoRsaHashedKeyGenParams : public WebCryptoRsaKeyGenParams {
public:
- WebCryptoRsaOaepParams(const WebCryptoAlgorithm& hash, bool hasLabel, const unsigned char* label, unsigned labelSize)
- : WebCryptoAlgorithmParams(WebCryptoAlgorithmParamsTypeRsaOaepParams)
+ explicit WebCryptoRsaHashedKeyGenParams(const WebCryptoAlgorithm& hash, unsigned modulusLengthBits, const unsigned char* publicExponent, unsigned publicExponentSize)
+ : WebCryptoRsaKeyGenParams(modulusLengthBits, publicExponent, publicExponentSize)
, m_hash(hash)
- , m_hasLabel(hasLabel)
- , m_optionalLabel(label, labelSize)
{
BLINK_ASSERT(!hash.isNull());
- BLINK_ASSERT(hasLabel || !labelSize);
}
+ virtual WebCryptoAlgorithmParamsType type() const { return WebCryptoAlgorithmParamsTypeRsaHashedKeyGenParams; }
+
const WebCryptoAlgorithm& hash() const { return m_hash; }
+private:
+ const WebCryptoAlgorithm m_hash;
+};
+
+class WebCryptoRsaOaepParams : public WebCryptoAlgorithmParams {
+public:
+ WebCryptoRsaOaepParams(bool hasLabel, const unsigned char* label, unsigned labelSize)
+ : m_hasLabel(hasLabel)
+ , m_optionalLabel(label, labelSize)
+ {
+ BLINK_ASSERT(hasLabel || !labelSize);
+ }
+
+ virtual WebCryptoAlgorithmParamsType type() const { return WebCryptoAlgorithmParamsTypeRsaOaepParams; }
+
bool hasLabel() const { return m_hasLabel; }
const WebVector<unsigned char>& optionalLabel() const { return m_optionalLabel; }
private:
- const WebCryptoAlgorithm m_hash;
const bool m_hasLabel;
const WebVector<unsigned char> m_optionalLabel;
};
« no previous file with comments | « public/platform/WebCryptoAlgorithm.h ('k') | public/platform/WebCryptoKey.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698