Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / public / platform / WebCryptoKeyAlgorithm.h
blobdf96d303b0d132250c7bcd03db1a5f9eb649b8d7
1 /*
2 * Copyright (C) 2014 Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met:
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
13 * distribution.
14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 #ifndef WebCryptoKeyAlgorithm_h
32 #define WebCryptoKeyAlgorithm_h
34 #include "WebCommon.h"
35 #include "WebCryptoAlgorithm.h"
36 #include "WebCryptoKeyAlgorithmParams.h"
37 #include "WebPrivatePtr.h"
39 #if INSIDE_BLINK
40 #include "wtf/PassOwnPtr.h"
41 #endif
43 namespace blink {
45 class WebCryptoKeyAlgorithmPrivate;
47 // WebCryptoKeyAlgorithm represents the algorithm used to generate a key.
48 // * Immutable
49 // * Threadsafe
50 // * Copiable (cheaply)
51 class WebCryptoKeyAlgorithm {
52 public:
53 WebCryptoKeyAlgorithm() { }
55 #if INSIDE_BLINK
56 BLINK_PLATFORM_EXPORT WebCryptoKeyAlgorithm(WebCryptoAlgorithmId, PassOwnPtr<WebCryptoKeyAlgorithmParams>);
57 #endif
59 // FIXME: Delete this in favor of the create*() functions.
60 BLINK_PLATFORM_EXPORT static WebCryptoKeyAlgorithm adoptParamsAndCreate(WebCryptoAlgorithmId, WebCryptoKeyAlgorithmParams*);
62 BLINK_PLATFORM_EXPORT static WebCryptoKeyAlgorithm createAes(WebCryptoAlgorithmId, unsigned short keyLengthBits);
63 BLINK_PLATFORM_EXPORT static WebCryptoKeyAlgorithm createHmac(WebCryptoAlgorithmId hash, unsigned keyLengthBits);
64 BLINK_PLATFORM_EXPORT static WebCryptoKeyAlgorithm createRsaHashed(WebCryptoAlgorithmId, unsigned modulusLengthBits, const unsigned char* publicExponent, unsigned publicExponentSize, WebCryptoAlgorithmId hash);
65 BLINK_PLATFORM_EXPORT static WebCryptoKeyAlgorithm createEc(WebCryptoAlgorithmId, WebCryptoNamedCurve);
66 BLINK_PLATFORM_EXPORT static WebCryptoKeyAlgorithm createWithoutParams(WebCryptoAlgorithmId);
68 ~WebCryptoKeyAlgorithm() { reset(); }
70 WebCryptoKeyAlgorithm(const WebCryptoKeyAlgorithm& other) { assign(other); }
71 WebCryptoKeyAlgorithm& operator=(const WebCryptoKeyAlgorithm& other)
73 assign(other);
74 return *this;
77 BLINK_PLATFORM_EXPORT bool isNull() const;
79 BLINK_PLATFORM_EXPORT WebCryptoAlgorithmId id() const;
81 BLINK_PLATFORM_EXPORT WebCryptoKeyAlgorithmParamsType paramsType() const;
83 // Returns the type-specific parameters for this key. If the requested
84 // parameters are not applicable (for instance an HMAC key does not have
85 // any AES parameters) then returns 0.
86 BLINK_PLATFORM_EXPORT WebCryptoAesKeyAlgorithmParams* aesParams() const;
87 BLINK_PLATFORM_EXPORT WebCryptoHmacKeyAlgorithmParams* hmacParams() const;
88 BLINK_PLATFORM_EXPORT WebCryptoRsaHashedKeyAlgorithmParams* rsaHashedParams() const;
89 BLINK_PLATFORM_EXPORT WebCryptoEcKeyAlgorithmParams* ecParams() const;
91 // Write the algorithm parameters to a dictionary.
92 BLINK_PLATFORM_EXPORT void writeToDictionary(WebCryptoKeyAlgorithmDictionary*) const;
94 private:
95 BLINK_PLATFORM_EXPORT void assign(const WebCryptoKeyAlgorithm& other);
96 BLINK_PLATFORM_EXPORT void reset();
98 WebPrivatePtr<WebCryptoKeyAlgorithmPrivate> m_private;
101 } // namespace blink
103 #endif