2 * Copyright (C) 2013 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 WebCryptoAlgorithm_h
32 #define WebCryptoAlgorithm_h
34 #include "WebCommon.h"
35 #include "WebPrivatePtr.h"
38 #include "wtf/PassOwnPtr.h"
43 enum WebCryptoAlgorithmId {
44 WebCryptoAlgorithmIdAesCbc,
45 WebCryptoAlgorithmIdHmac,
46 WebCryptoAlgorithmIdRsaSsaPkcs1v1_5,
47 WebCryptoAlgorithmIdRsaEsPkcs1v1_5,
48 WebCryptoAlgorithmIdSha1,
49 WebCryptoAlgorithmIdSha224,
50 WebCryptoAlgorithmIdSha256,
51 WebCryptoAlgorithmIdSha384,
52 WebCryptoAlgorithmIdSha512,
53 WebCryptoAlgorithmIdAesGcm,
54 WebCryptoAlgorithmIdRsaOaep,
55 WebCryptoAlgorithmIdAesCtr,
56 WebCryptoAlgorithmIdAesKw,
58 NumberOfWebCryptoAlgorithmId,
62 enum WebCryptoAlgorithmParamsType {
63 WebCryptoAlgorithmParamsTypeNone,
64 WebCryptoAlgorithmParamsTypeAesCbcParams,
65 WebCryptoAlgorithmParamsTypeAesKeyGenParams,
66 WebCryptoAlgorithmParamsTypeHmacParams,
67 WebCryptoAlgorithmParamsTypeHmacKeyParams,
68 WebCryptoAlgorithmParamsTypeRsaSsaParams,
69 WebCryptoAlgorithmParamsTypeRsaKeyGenParams,
70 WebCryptoAlgorithmParamsTypeAesGcmParams,
71 WebCryptoAlgorithmParamsTypeRsaOaepParams,
72 WebCryptoAlgorithmParamsTypeAesCtrParams,
75 class WebCryptoAesCbcParams;
76 class WebCryptoAesKeyGenParams;
77 class WebCryptoHmacParams;
78 class WebCryptoHmacKeyParams;
79 class WebCryptoRsaSsaParams;
80 class WebCryptoRsaKeyGenParams;
81 class WebCryptoAesGcmParams;
82 class WebCryptoRsaOaepParams;
83 class WebCryptoAesCtrParams;
85 class WebCryptoAlgorithmParams;
86 class WebCryptoAlgorithmPrivate;
88 // The WebCryptoAlgorithm represents a normalized algorithm and its parameters.
91 // * Copiable (cheaply)
93 // If WebCryptoAlgorithm "isNull()" then it is invalid to call any of the other
94 // methods on it (other than destruction, assignment, or isNull()).
95 class WebCryptoAlgorithm {
98 WebCryptoAlgorithm() { }
99 BLINK_PLATFORM_EXPORT WebCryptoAlgorithm(WebCryptoAlgorithmId, PassOwnPtr<WebCryptoAlgorithmParams>);
102 BLINK_PLATFORM_EXPORT static WebCryptoAlgorithm createNull();
103 BLINK_PLATFORM_EXPORT static WebCryptoAlgorithm adoptParamsAndCreate(WebCryptoAlgorithmId, WebCryptoAlgorithmParams*);
105 ~WebCryptoAlgorithm() { reset(); }
107 WebCryptoAlgorithm(const WebCryptoAlgorithm& other) { assign(other); }
108 WebCryptoAlgorithm& operator=(const WebCryptoAlgorithm& other)
114 BLINK_PLATFORM_EXPORT bool isNull() const;
116 BLINK_PLATFORM_EXPORT WebCryptoAlgorithmId id() const;
118 BLINK_PLATFORM_EXPORT WebCryptoAlgorithmParamsType paramsType() const;
120 // Retrieves the type-specific parameters. The algorithm contains at most 1
121 // type of parameters. Retrieving an invalid parameter will return 0.
122 BLINK_PLATFORM_EXPORT const WebCryptoAesCbcParams* aesCbcParams() const;
123 BLINK_PLATFORM_EXPORT const WebCryptoAesKeyGenParams* aesKeyGenParams() const;
124 BLINK_PLATFORM_EXPORT const WebCryptoHmacParams* hmacParams() const;
125 BLINK_PLATFORM_EXPORT const WebCryptoHmacKeyParams* hmacKeyParams() const;
126 BLINK_PLATFORM_EXPORT const WebCryptoRsaSsaParams* rsaSsaParams() const;
127 BLINK_PLATFORM_EXPORT const WebCryptoRsaKeyGenParams* rsaKeyGenParams() const;
128 BLINK_PLATFORM_EXPORT const WebCryptoAesGcmParams* aesGcmParams() const;
129 BLINK_PLATFORM_EXPORT const WebCryptoRsaOaepParams* rsaOaepParams() const;
130 BLINK_PLATFORM_EXPORT const WebCryptoAesCtrParams* aesCtrParams() const;
133 BLINK_PLATFORM_EXPORT void assign(const WebCryptoAlgorithm& other);
134 BLINK_PLATFORM_EXPORT void reset();
136 WebPrivatePtr<WebCryptoAlgorithmPrivate> m_private;