Chromium Code Reviews| Index: public/platform/WebCryptoAlgorithmParams.h |
| diff --git a/public/platform/WebCryptoAlgorithmParams.h b/public/platform/WebCryptoAlgorithmParams.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..f64492e389adf76bed1f4a1cb1308e88423bd0e9 |
| --- /dev/null |
| +++ b/public/platform/WebCryptoAlgorithmParams.h |
| @@ -0,0 +1,110 @@ |
| +/* |
| + * Copyright (C) 2013 Google Inc. All rights reserved. |
| + * |
| + * Redistribution and use in source and binary forms, with or without |
| + * modification, are permitted provided that the following conditions are |
| + * met: |
| + * |
| + * * Redistributions of source code must retain the above copyright |
| + * notice, this list of conditions and the following disclaimer. |
| + * * Redistributions in binary form must reproduce the above |
| + * copyright notice, this list of conditions and the following disclaimer |
| + * in the documentation and/or other materials provided with the |
| + * distribution. |
| + * * Neither the name of Google Inc. nor the names of its |
| + * contributors may be used to endorse or promote products derived from |
| + * this software without specific prior written permission. |
| + * |
| + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| + */ |
| + |
| +#ifndef WebCryptoAlgorithmParams_h |
| +#define WebCryptoAlgorithmParams_h |
| + |
| +#include "WebCommon.h" |
| +#include "WebCryptoAlgorithm.h" |
| + |
| +namespace WebKit { |
| + |
| +// Base class for all the algorithm parameters. |
| +// |
| +// NOTE: For documentation on the meaning of each of the parameters see the Web |
| +// Crypto spec. Parameters have the same name (minus "WebCrypto" prefix). |
|
abarth-chromium
2013/07/02 06:46:36
Please add a link to the spec.
eroman
2013/07/02 08:12:27
Done.
|
| +class WebCryptoAlgorithmParams { |
| +public: |
| + WebCryptoAlgorithmParams(WebCryptoAlgorithmParamsType type) |
| + : m_type(type) |
| + { |
| + } |
| + |
| + virtual ~WebCryptoAlgorithmParams() { } |
| + |
| + WebCryptoAlgorithmParamsType type() const { return m_type; } |
| + |
| +protected: |
| + // Helper class for a chunk of owned immutable data. |
|
abarth-chromium
2013/07/02 06:46:36
We should be able to just use WebVector
eroman
2013/07/02 08:12:27
Done.
|
| + class Bytes { |
| + public: |
| + // Makes a copy of |data|. |
| + Bytes(const unsigned char*, size_t); |
| + ~Bytes(); |
| + |
| + const unsigned char* data() const { return m_data; } |
| + size_t size() const { return m_size; } |
| + |
| + private: |
| + Bytes(const Bytes&); |
| + Bytes& operator=(const Bytes&); |
| + |
| + const unsigned char* m_data; |
| + size_t m_size; |
| + }; |
| + |
| +private: |
| + WebCryptoAlgorithmParamsType m_type; |
| +}; |
| + |
| +class WebCryptoAesCbcParams : public WebCryptoAlgorithmParams { |
| +public: |
| + WebCryptoAesCbcParams(unsigned char* iv, size_t ivSize) |
| + : WebCryptoAlgorithmParams(AesCbcParams) |
| + , m_iv(iv, ivSize) |
| + { |
| + } |
| + |
| + // The initialization vector. MUST be 16 bytes. |
|
abarth-chromium
2013/07/02 06:46:36
Can you enforce that with an ASSERT rather than a
eroman
2013/07/02 08:12:27
Removed the comment.
I had copy-pasted it from th
|
| + const unsigned char* iv() const { return m_iv.data(); } |
| + size_t ivSize() const { return m_iv.size(); } |
| + |
| +private: |
| + const Bytes m_iv; |
| +}; |
| + |
| +class WebCryptoAesKeyGenParams : public WebCryptoAlgorithmParams { |
| +public: |
| + WebCryptoAesKeyGenParams(unsigned short length) |
| + : WebCryptoAlgorithmParams(AesKeyGenParams) |
| + , m_length(length) |
| + { |
| + } |
| + |
| + // The length, in bits, of the key. |
| + unsigned short length() const { return m_length; } |
| + |
| +private: |
| + const unsigned short m_length; |
| +}; |
| + |
| +} // namespace WebKit |
| + |
| +#endif |