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

Side by Side Diff: third_party/WebKit/Source/modules/crypto/SubtleCrypto.cpp

Issue 2218533002: Backporting JSONValues from protocol::Values (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Switch back to partition allocator Created 4 years, 4 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
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 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 return false; 73 return false;
74 destination->setString(property, value); 74 destination->setString(property, value);
75 return true; 75 return true;
76 } 76 }
77 77
78 static bool copySequenceOfStringProperty(const char* property, const Dictionary& source, JSONObject* destination) 78 static bool copySequenceOfStringProperty(const char* property, const Dictionary& source, JSONObject* destination)
79 { 79 {
80 Vector<String> value; 80 Vector<String> value;
81 if (!DictionaryHelper::get(source, property, value)) 81 if (!DictionaryHelper::get(source, property, value))
82 return false; 82 return false;
83 RefPtr<JSONArray> jsonArray = JSONArray::create(); 83 std::unique_ptr<JSONArray> jsonArray = JSONArray::create();
84 for (unsigned i = 0; i < value.size(); ++i) 84 for (unsigned i = 0; i < value.size(); ++i)
85 jsonArray->pushString(value[i]); 85 jsonArray->pushString(value[i]);
86 destination->setArray(property, jsonArray.release()); 86 destination->setArray(property, std::move(jsonArray));
87 return true; 87 return true;
88 } 88 }
89 89
90 // Parses a JsonWebKey dictionary. On success writes the result to 90 // Parses a JsonWebKey dictionary. On success writes the result to
91 // |jsonUtf8| as a UTF8-encoded JSON octet string and returns true. 91 // |jsonUtf8| as a UTF8-encoded JSON octet string and returns true.
92 // On failure sets an error on |result| and returns false. 92 // On failure sets an error on |result| and returns false.
93 // 93 //
94 // Note: The choice of output as an octet string is to facilitate interop 94 // Note: The choice of output as an octet string is to facilitate interop
95 // with the non-JWK formats, but does mean there is a second parsing step. 95 // with the non-JWK formats, but does mean there is a second parsing step.
96 // This design choice should be revisited after crbug.com/614385). 96 // This design choice should be revisited after crbug.com/614385).
(...skipping 29 matching lines...) Expand all
126 // DOMString t; 126 // DOMString t;
127 // }; 127 // };
128 static bool parseJsonWebKey(const Dictionary& dict, WebVector<uint8_t>& jsonUtf8 , CryptoResult* result) 128 static bool parseJsonWebKey(const Dictionary& dict, WebVector<uint8_t>& jsonUtf8 , CryptoResult* result)
129 { 129 {
130 // TODO(eroman): This implementation is incomplete and not spec compliant: 130 // TODO(eroman): This implementation is incomplete and not spec compliant:
131 // * Properties need to be read in the definition order above 131 // * Properties need to be read in the definition order above
132 // * Preserve the type of optional parameters (crbug.com/385376) 132 // * Preserve the type of optional parameters (crbug.com/385376)
133 // * Parse "oth" (crbug.com/441396) 133 // * Parse "oth" (crbug.com/441396)
134 // * Fail with TypeError (not DataError) if the input does not conform 134 // * Fail with TypeError (not DataError) if the input does not conform
135 // to a JsonWebKey 135 // to a JsonWebKey
136 RefPtr<JSONObject> jsonObject = JSONObject::create(); 136 std::unique_ptr<JSONObject> jsonObject = JSONObject::create();
137 137
138 if (!copyStringProperty("kty", dict, jsonObject.get())) { 138 if (!copyStringProperty("kty", dict, jsonObject.get())) {
139 result->completeWithError(WebCryptoErrorTypeData, "The required JWK memb er \"kty\" was missing"); 139 result->completeWithError(WebCryptoErrorTypeData, "The required JWK memb er \"kty\" was missing");
140 return false; 140 return false;
141 } 141 }
142 142
143 copyStringProperty("use", dict, jsonObject.get()); 143 copyStringProperty("use", dict, jsonObject.get());
144 copySequenceOfStringProperty("key_ops", dict, jsonObject.get()); 144 copySequenceOfStringProperty("key_ops", dict, jsonObject.get());
145 copyStringProperty("alg", dict, jsonObject.get()); 145 copyStringProperty("alg", dict, jsonObject.get());
146 146
(...skipping 510 matching lines...) Expand 10 before | Expand all | Expand 10 after
657 // normative requirement is enforced by the platform implementation in the 657 // normative requirement is enforced by the platform implementation in the
658 // call below. 658 // call below.
659 659
660 histogramAlgorithmAndKey(scriptState->getExecutionContext(), normalizedAlgor ithm, baseKey->key()); 660 histogramAlgorithmAndKey(scriptState->getExecutionContext(), normalizedAlgor ithm, baseKey->key());
661 histogramAlgorithm(scriptState->getExecutionContext(), normalizedDerivedKeyA lgorithm); 661 histogramAlgorithm(scriptState->getExecutionContext(), normalizedDerivedKeyA lgorithm);
662 Platform::current()->crypto()->deriveKey(normalizedAlgorithm, baseKey->key() , normalizedDerivedKeyAlgorithm, keyLengthAlgorithm, extractable, keyUsages, res ult->result()); 662 Platform::current()->crypto()->deriveKey(normalizedAlgorithm, baseKey->key() , normalizedDerivedKeyAlgorithm, keyLengthAlgorithm, extractable, keyUsages, res ult->result());
663 return promise; 663 return promise;
664 } 664 }
665 665
666 } // namespace blink 666 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698