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

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

Issue 195543002: [webcrypto] Implement structured clone of keys (blink-side). (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Update serialized-script-value.html for version bump Created 6 years, 9 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 | Annotate | Revision Log
« no previous file with comments | « Source/platform/exported/WebCryptoAlgorithm.cpp ('k') | public/platform/WebCrypto.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) 2014 Google Inc. All rights reserved. 2 * Copyright (C) 2014 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 18 matching lines...) Expand all
29 */ 29 */
30 30
31 #include "config.h" 31 #include "config.h"
32 #include "public/platform/WebCryptoKeyAlgorithm.h" 32 #include "public/platform/WebCryptoKeyAlgorithm.h"
33 33
34 #include "wtf/OwnPtr.h" 34 #include "wtf/OwnPtr.h"
35 #include "wtf/ThreadSafeRefCounted.h" 35 #include "wtf/ThreadSafeRefCounted.h"
36 36
37 namespace blink { 37 namespace blink {
38 38
39 // FIXME: Remove the need for this.
40 WebCryptoAlgorithm createHash(WebCryptoAlgorithmId hash)
41 {
42 return WebCryptoAlgorithm::adoptParamsAndCreate(hash, 0);
43 }
44
39 class WebCryptoKeyAlgorithmPrivate : public ThreadSafeRefCounted<WebCryptoKeyAlg orithmPrivate> { 45 class WebCryptoKeyAlgorithmPrivate : public ThreadSafeRefCounted<WebCryptoKeyAlg orithmPrivate> {
40 public: 46 public:
41 WebCryptoKeyAlgorithmPrivate(WebCryptoAlgorithmId id, PassOwnPtr<WebCryptoKe yAlgorithmParams> params) 47 WebCryptoKeyAlgorithmPrivate(WebCryptoAlgorithmId id, PassOwnPtr<WebCryptoKe yAlgorithmParams> params)
42 : id(id) 48 : id(id)
43 , params(params) 49 , params(params)
44 { 50 {
45 } 51 }
46 52
47 WebCryptoAlgorithmId id; 53 WebCryptoAlgorithmId id;
48 OwnPtr<WebCryptoKeyAlgorithmParams> params; 54 OwnPtr<WebCryptoKeyAlgorithmParams> params;
49 }; 55 };
50 56
51 WebCryptoKeyAlgorithm::WebCryptoKeyAlgorithm(WebCryptoAlgorithmId id, PassOwnPtr <WebCryptoKeyAlgorithmParams> params) 57 WebCryptoKeyAlgorithm::WebCryptoKeyAlgorithm(WebCryptoAlgorithmId id, PassOwnPtr <WebCryptoKeyAlgorithmParams> params)
52 : m_private(adoptRef(new WebCryptoKeyAlgorithmPrivate(id, params))) 58 : m_private(adoptRef(new WebCryptoKeyAlgorithmPrivate(id, params)))
53 { 59 {
54 } 60 }
55 61
56 WebCryptoKeyAlgorithm WebCryptoKeyAlgorithm::adoptParamsAndCreate(WebCryptoAlgor ithmId id, WebCryptoKeyAlgorithmParams* params) 62 WebCryptoKeyAlgorithm WebCryptoKeyAlgorithm::adoptParamsAndCreate(WebCryptoAlgor ithmId id, WebCryptoKeyAlgorithmParams* params)
57 { 63 {
58 return WebCryptoKeyAlgorithm(id, adoptPtr(params)); 64 return WebCryptoKeyAlgorithm(id, adoptPtr(params));
59 } 65 }
60 66
67 WebCryptoKeyAlgorithm WebCryptoKeyAlgorithm::createAes(WebCryptoAlgorithmId id, unsigned short keyLengthBits)
68 {
69 // FIXME: Verify that id is an AES algorithm.
70 // FIXME: Move this somewhere more general.
71 if (keyLengthBits != 128 && keyLengthBits != 192 && keyLengthBits != 256)
72 return WebCryptoKeyAlgorithm();
73 return WebCryptoKeyAlgorithm(id, adoptPtr(new WebCryptoAesKeyAlgorithmParams (keyLengthBits)));
74 }
75
76 WebCryptoKeyAlgorithm WebCryptoKeyAlgorithm::createHmac(WebCryptoAlgorithmId has h, unsigned keyLengthBits)
77 {
78 if (!WebCryptoAlgorithm::isHash(hash))
79 return WebCryptoKeyAlgorithm();
80 return WebCryptoKeyAlgorithm(WebCryptoAlgorithmIdHmac, adoptPtr(new WebCrypt oHmacKeyAlgorithmParams(createHash(hash), keyLengthBits)));
81 }
82
83 WebCryptoKeyAlgorithm WebCryptoKeyAlgorithm::createRsa(WebCryptoAlgorithmId id, unsigned modulusLengthBits, const unsigned char* publicExponent, unsigned public ExponentSize)
84 {
85 // FIXME: Verify that id is an RSA algorithm without a hash
86 return WebCryptoKeyAlgorithm(id, adoptPtr(new WebCryptoRsaKeyAlgorithmParams (modulusLengthBits, publicExponent, publicExponentSize)));
87 }
88
89 WebCryptoKeyAlgorithm WebCryptoKeyAlgorithm::createRsaHashed(WebCryptoAlgorithmI d id, unsigned modulusLengthBits, const unsigned char* publicExponent, unsigned publicExponentSize, WebCryptoAlgorithmId hash)
90 {
91 // FIXME: Verify that id is an RSA algorithm which expects a hash
92 if (!WebCryptoAlgorithm::isHash(hash))
93 return WebCryptoKeyAlgorithm();
94 return WebCryptoKeyAlgorithm(id, adoptPtr(new WebCryptoRsaHashedKeyAlgorithm Params(modulusLengthBits, publicExponent, publicExponentSize, createHash(hash))) );
95 }
96
61 bool WebCryptoKeyAlgorithm::isNull() const 97 bool WebCryptoKeyAlgorithm::isNull() const
62 { 98 {
63 return m_private.isNull(); 99 return m_private.isNull();
64 } 100 }
65 101
66 WebCryptoAlgorithmId WebCryptoKeyAlgorithm::id() const 102 WebCryptoAlgorithmId WebCryptoKeyAlgorithm::id() const
67 { 103 {
68 ASSERT(!isNull()); 104 ASSERT(!isNull());
69 return m_private->id; 105 return m_private->id;
70 } 106 }
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 { 149 {
114 m_private = other.m_private; 150 m_private = other.m_private;
115 } 151 }
116 152
117 void WebCryptoKeyAlgorithm::reset() 153 void WebCryptoKeyAlgorithm::reset()
118 { 154 {
119 m_private.reset(); 155 m_private.reset();
120 } 156 }
121 157
122 } // namespace blink 158 } // namespace blink
OLDNEW
« no previous file with comments | « Source/platform/exported/WebCryptoAlgorithm.cpp ('k') | public/platform/WebCrypto.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698