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

Side by Side Diff: Source/platform/exported/WebCryptoAlgorithm.cpp

Issue 312393004: Expose WebCrypto's lookupAlgorithmInfo. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@share_normalize
Patch Set: Created 6 years, 6 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 unified diff | Download patch
« no previous file with comments | « Source/modules/crypto/NormalizeAlgorithm.cpp ('k') | public/platform/WebCryptoAlgorithm.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2013 Google Inc. All rights reserved. 2 * Copyright (C) 2013 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 17 matching lines...) Expand all
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30 30
31 #include "config.h" 31 #include "config.h"
32 #include "public/platform/WebCryptoAlgorithm.h" 32 #include "public/platform/WebCryptoAlgorithm.h"
33 33
34 #include "public/platform/WebCryptoAlgorithmParams.h" 34 #include "public/platform/WebCryptoAlgorithmParams.h"
35 #include "wtf/OwnPtr.h" 35 #include "wtf/OwnPtr.h"
36 #include "wtf/ThreadSafeRefCounted.h" 36 #include "wtf/ThreadSafeRefCounted.h"
37 37
38 namespace {
39 const char* kAlgorithmNameAesCbc = "AES-CBC";
40 const char* kAlgorithmNameHmac = "HMAC";
41 const char* kAlgorithmNameRsaSsaPkcs1v15 = "RSASSA-PKCS1-v1_5";
42 const char* kAlgorithmNameSha1 = "SHA-1";
43 const char* kAlgorithmNameSha256 = "SHA-256";
44 const char* kAlgorithmNameSha384 = "SHA-384";
45 const char* kAlgorithmNameSha512 = "SHA-512";
46 const char* kAlgorithmNameAesGcm = "AES-GCM";
47 const char* kAlgorithmNameRsaOaep = "RSA-OAEP";
48 const char* kAlgorithmNameAesCtr = "AES-CTR";
49 const char* kAlgorithmNameAesKw = "AES-KW";
abarth-chromium 2014/06/06 17:10:09 char* -> char[]
pneubeck (no reviews) 2014/06/10 12:33:02 Done.
50 }
51
38 namespace blink { 52 namespace blink {
39 53
40 class WebCryptoAlgorithmPrivate : public ThreadSafeRefCounted<WebCryptoAlgorithm Private> { 54 class WebCryptoAlgorithmPrivate : public ThreadSafeRefCounted<WebCryptoAlgorithm Private> {
41 public: 55 public:
42 WebCryptoAlgorithmPrivate(WebCryptoAlgorithmId id, PassOwnPtr<WebCryptoAlgor ithmParams> params) 56 WebCryptoAlgorithmPrivate(WebCryptoAlgorithmId id, PassOwnPtr<WebCryptoAlgor ithmParams> params)
43 : id(id) 57 : id(id)
44 , params(params) 58 , params(params)
45 { 59 {
46 } 60 }
47 61
48 WebCryptoAlgorithmId id; 62 WebCryptoAlgorithmId id;
49 OwnPtr<WebCryptoAlgorithmParams> params; 63 OwnPtr<WebCryptoAlgorithmParams> params;
50 }; 64 };
51 65
52 WebCryptoAlgorithm::WebCryptoAlgorithm(WebCryptoAlgorithmId id, PassOwnPtr<WebCr yptoAlgorithmParams> params) 66 WebCryptoAlgorithm::WebCryptoAlgorithm(WebCryptoAlgorithmId id, PassOwnPtr<WebCr yptoAlgorithmParams> params)
53 : m_private(adoptRef(new WebCryptoAlgorithmPrivate(id, params))) 67 : m_private(adoptRef(new WebCryptoAlgorithmPrivate(id, params)))
54 { 68 {
55 } 69 }
56 70
57 WebCryptoAlgorithm WebCryptoAlgorithm::createNull() 71 WebCryptoAlgorithm WebCryptoAlgorithm::createNull()
58 { 72 {
59 return WebCryptoAlgorithm(); 73 return WebCryptoAlgorithm();
60 } 74 }
61 75
62 WebCryptoAlgorithm WebCryptoAlgorithm::adoptParamsAndCreate(WebCryptoAlgorithmId id, WebCryptoAlgorithmParams* params) 76 WebCryptoAlgorithm WebCryptoAlgorithm::adoptParamsAndCreate(WebCryptoAlgorithmId id, WebCryptoAlgorithmParams* params)
63 { 77 {
64 return WebCryptoAlgorithm(id, adoptPtr(params)); 78 return WebCryptoAlgorithm(id, adoptPtr(params));
65 } 79 }
66 80
81 const char* WebCryptoAlgorithm::idToName(blink::WebCryptoAlgorithmId id)
82 {
83 switch (id) {
84 case blink::WebCryptoAlgorithmIdAesCbc:
85 return kAlgorithmNameAesCbc;
86 case blink::WebCryptoAlgorithmIdHmac:
87 return kAlgorithmNameHmac;
88 case blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5:
89 return kAlgorithmNameRsaSsaPkcs1v15;
90 case blink::WebCryptoAlgorithmIdSha1:
91 return kAlgorithmNameSha1;
92 case blink::WebCryptoAlgorithmIdSha256:
93 return kAlgorithmNameSha256;
94 case blink::WebCryptoAlgorithmIdSha384:
95 return kAlgorithmNameSha384;
96 case blink::WebCryptoAlgorithmIdSha512:
97 return kAlgorithmNameSha512;
98 case blink::WebCryptoAlgorithmIdAesGcm:
99 return kAlgorithmNameAesGcm;
100 case blink::WebCryptoAlgorithmIdRsaOaep:
101 return kAlgorithmNameRsaOaep;
102 case blink::WebCryptoAlgorithmIdAesCtr:
103 return kAlgorithmNameAesCtr;
104 case blink::WebCryptoAlgorithmIdAesKw:
105 return kAlgorithmNameAesKw;
106 }
abarth-chromium 2014/06/06 17:10:08 Can we use a static array instead of a switch stat
pneubeck (no reviews) 2014/06/06 18:08:32 I did this so that the compiler can potentially ch
107 ASSERT_NOT_REACHED();
108 return 0;
109 }
110
67 bool WebCryptoAlgorithm::isNull() const 111 bool WebCryptoAlgorithm::isNull() const
68 { 112 {
69 return m_private.isNull(); 113 return m_private.isNull();
70 } 114 }
71 115
72 WebCryptoAlgorithmId WebCryptoAlgorithm::id() const 116 WebCryptoAlgorithmId WebCryptoAlgorithm::id() const
73 { 117 {
74 ASSERT(!isNull()); 118 ASSERT(!isNull());
75 return m_private->id; 119 return m_private->id;
76 } 120 }
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 { 223 {
180 m_private = other.m_private; 224 m_private = other.m_private;
181 } 225 }
182 226
183 void WebCryptoAlgorithm::reset() 227 void WebCryptoAlgorithm::reset()
184 { 228 {
185 m_private.reset(); 229 m_private.reset();
186 } 230 }
187 231
188 } // namespace blink 232 } // namespace blink
OLDNEW
« no previous file with comments | « Source/modules/crypto/NormalizeAlgorithm.cpp ('k') | public/platform/WebCryptoAlgorithm.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698