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

Side by Side Diff: Source/modules/crypto/Crypto.cpp

Issue 16820007: Expose crypto.getRandomValues() to workers. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 7 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 | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2011 Google Inc. All rights reserved. 2 * Copyright (C) 2011 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 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 7 *
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. 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 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 12 matching lines...) Expand all
23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */ 27 */
28 28
29 29
30 #include "config.h" 30 #include "config.h"
31 #include "modules/crypto/Crypto.h" 31 #include "modules/crypto/Crypto.h"
32 32
33 #include "core/dom/ExceptionCode.h"
34 #include "wtf/ArrayBufferView.h"
35 #include "wtf/CryptographicallyRandomNumber.h"
36
37 namespace WebCore { 33 namespace WebCore {
38 34
39 namespace {
40
41 bool isIntegerArray(ArrayBufferView* array)
42 {
43 ArrayBufferView::ViewType type = array->getType();
44 return type == ArrayBufferView::TypeInt8
45 || type == ArrayBufferView::TypeUint8
46 || type == ArrayBufferView::TypeUint8Clamped
47 || type == ArrayBufferView::TypeInt16
48 || type == ArrayBufferView::TypeUint16
49 || type == ArrayBufferView::TypeInt32
50 || type == ArrayBufferView::TypeUint32;
51 }
52
53 }
54
55 Crypto::Crypto() 35 Crypto::Crypto()
56 { 36 {
57 ScriptWrappable::init(this); 37 ScriptWrappable::init(this);
58 } 38 }
59 39
60 void Crypto::getRandomValues(ArrayBufferView* array, ExceptionCode& ec)
61 {
62 if (!array || !isIntegerArray(array)) {
63 ec = TYPE_MISMATCH_ERR;
64 return;
65 }
66 if (array->byteLength() > 65536) {
67 ec = QUOTA_EXCEEDED_ERR;
68 return;
69 }
70 cryptographicallyRandomValues(array->baseAddress(), array->byteLength());
71 }
72
73 SubtleCrypto* Crypto::subtle() 40 SubtleCrypto* Crypto::subtle()
74 { 41 {
75 if (!m_subtleCrypto) 42 if (!m_subtleCrypto)
76 m_subtleCrypto = SubtleCrypto::create(); 43 m_subtleCrypto = SubtleCrypto::create();
77 return m_subtleCrypto.get(); 44 return m_subtleCrypto.get();
78 } 45 }
79 46
80 } 47 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698