OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/child/webcrypto/jwk.h" | 5 #include "content/child/webcrypto/jwk.h" |
6 | 6 |
7 #include "base/base64.h" | 7 #include "base/base64.h" |
8 #include "base/json/json_reader.h" | 8 #include "base/json/json_reader.h" |
9 #include "base/json/json_writer.h" | 9 #include "base/json/json_writer.h" |
10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
(...skipping 430 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
441 if (has_jwk_alg && jwk_alg_value != expected_alg) | 441 if (has_jwk_alg && jwk_alg_value != expected_alg) |
442 return Status::ErrorJwkAlgorithmInconsistent(); | 442 return Status::ErrorJwkAlgorithmInconsistent(); |
443 | 443 |
444 return Status::Success(); | 444 return Status::Success(); |
445 } | 445 } |
446 | 446 |
447 JwkWriter::JwkWriter(const std::string& algorithm, | 447 JwkWriter::JwkWriter(const std::string& algorithm, |
448 bool extractable, | 448 bool extractable, |
449 blink::WebCryptoKeyUsageMask usages, | 449 blink::WebCryptoKeyUsageMask usages, |
450 const std::string& kty) { | 450 const std::string& kty) { |
451 dict_.SetString("alg", algorithm); | 451 if (!algorithm.empty()) |
| 452 dict_.SetString("alg", algorithm); |
452 dict_.Set("key_ops", CreateJwkKeyOpsFromWebCryptoUsages(usages)); | 453 dict_.Set("key_ops", CreateJwkKeyOpsFromWebCryptoUsages(usages)); |
453 dict_.SetBoolean("ext", extractable); | 454 dict_.SetBoolean("ext", extractable); |
454 dict_.SetString("kty", kty); | 455 dict_.SetString("kty", kty); |
455 } | 456 } |
456 | 457 |
457 void JwkWriter::SetString(const std::string& member_name, | 458 void JwkWriter::SetString(const std::string& member_name, |
458 const std::string& value) { | 459 const std::string& value) { |
459 dict_.SetString(member_name, value); | 460 dict_.SetString(member_name, value); |
460 } | 461 } |
461 | 462 |
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
702 | 703 |
703 std::string Base64EncodeUrlSafe(const std::vector<uint8_t>& input) { | 704 std::string Base64EncodeUrlSafe(const std::vector<uint8_t>& input) { |
704 const base::StringPiece string_piece( | 705 const base::StringPiece string_piece( |
705 reinterpret_cast<const char*>(vector_as_array(&input)), input.size()); | 706 reinterpret_cast<const char*>(vector_as_array(&input)), input.size()); |
706 return Base64EncodeUrlSafe(string_piece); | 707 return Base64EncodeUrlSafe(string_piece); |
707 } | 708 } |
708 | 709 |
709 } // namespace webcrypto | 710 } // namespace webcrypto |
710 | 711 |
711 } // namespace content | 712 } // namespace content |
OLD | NEW |