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
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
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"
40 #include "wtf/PassOwnPtr.h"
45 class WebCryptoKeyAlgorithmPrivate
;
47 // WebCryptoKeyAlgorithm represents the algorithm used to generate a key.
50 // * Copiable (cheaply)
51 class WebCryptoKeyAlgorithm
{
53 WebCryptoKeyAlgorithm() { }
56 BLINK_PLATFORM_EXPORT
WebCryptoKeyAlgorithm(WebCryptoAlgorithmId
, PassOwnPtr
<WebCryptoKeyAlgorithmParams
>);
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
)
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;
95 BLINK_PLATFORM_EXPORT
void assign(const WebCryptoKeyAlgorithm
& other
);
96 BLINK_PLATFORM_EXPORT
void reset();
98 WebPrivatePtr
<WebCryptoKeyAlgorithmPrivate
> m_private
;