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

Side by Side Diff: components/webcrypto/jwk.h

Issue 1355873002: [refactor] More post-NSS WebCrypto cleanups (utility functions). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix bug Created 5 years, 3 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 // 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 #ifndef COMPONENTS_WEBCRYPTO_JWK_H_ 5 #ifndef COMPONENTS_WEBCRYPTO_JWK_H_
6 #define COMPONENTS_WEBCRYPTO_JWK_H_ 6 #define COMPONENTS_WEBCRYPTO_JWK_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 void SetBytes(const std::string& member_name, const CryptoData& value); 119 void SetBytes(const std::string& member_name, const CryptoData& value);
120 120
121 // Flattens the JWK to JSON (UTF-8 encoded if necessary, however in practice 121 // Flattens the JWK to JSON (UTF-8 encoded if necessary, however in practice
122 // it will be ASCII). 122 // it will be ASCII).
123 void ToJson(std::vector<uint8_t>* utf8_bytes) const; 123 void ToJson(std::vector<uint8_t>* utf8_bytes) const;
124 124
125 private: 125 private:
126 base::DictionaryValue dict_; 126 base::DictionaryValue dict_;
127 }; 127 };
128 128
129 // Writes a JWK-formatted symmetric key to |jwk_key_data|.
130 // * raw_key_data: The actual key data
131 // * algorithm: The JWK algorithm name (i.e. "alg")
132 // * extractable: The JWK extractability (i.e. "ext")
133 // * usages: The JWK usages (i.e. "key_ops")
134 void WriteSecretKeyJwk(const CryptoData& raw_key_data,
135 const std::string& algorithm,
136 bool extractable,
137 blink::WebCryptoKeyUsageMask usages,
138 std::vector<uint8_t>* jwk_key_data);
139
140 // Parses a UTF-8 encoded JWK (key_data), and extracts the key material to
141 // |*raw_key_data|. Returns Status::Success() on success, otherwise an error.
142 // In order for this to succeed:
143 // * expected_extractable must be consistent with the JWK's "ext", if
144 // present.
145 // * expected_usages must be a subset of the JWK's "key_ops" if present.
146 Status ReadSecretKeyNoExpectedAlg(const CryptoData& key_data,
147 bool expected_extractable,
148 blink::WebCryptoKeyUsageMask expected_usages,
149 std::vector<uint8_t>* raw_key_data,
150 JwkReader* jwk);
davidben 2015/09/18 22:16:00 Is the intent that this file just be a generic JWK
eroman 2015/09/18 23:13:23 Yes. I would like jwk.{h, cc} to just contain the
151
152 // This decodes JWK's flavor of base64 encoding, as described by: 129 // This decodes JWK's flavor of base64 encoding, as described by:
153 // https://tools.ietf.org/html/draft-ietf-jose-json-web-signature-36#section-2 130 // https://tools.ietf.org/html/draft-ietf-jose-json-web-signature-36#section-2
154 // 131 //
155 // In essence it is RFC 4648 'base64url' encoding where padding is omitted. 132 // In essence it is RFC 4648 'base64url' encoding where padding is omitted.
156 bool Base64DecodeUrlSafe(const std::string& input, std::string* output); 133 bool Base64DecodeUrlSafe(const std::string& input, std::string* output);
157 134
158 // Encodes |input| using JWK's flavor of base64 encoding. See the description 135 // Encodes |input| using JWK's flavor of base64 encoding. See the description
159 // above for details. 136 // above for details.
160 std::string Base64EncodeUrlSafe(const base::StringPiece& input); 137 std::string Base64EncodeUrlSafe(const base::StringPiece& input);
161 std::string Base64EncodeUrlSafe(const std::vector<uint8_t>& input); 138 std::string Base64EncodeUrlSafe(const std::vector<uint8_t>& input);
162 139
163 // Converts a JWK "key_ops" array to the corresponding WebCrypto usages. Used by 140 // Converts a JWK "key_ops" array to the corresponding WebCrypto usages. Used by
164 // testing. 141 // testing.
165 Status GetWebCryptoUsagesFromJwkKeyOpsForTest( 142 Status GetWebCryptoUsagesFromJwkKeyOpsForTest(
166 const base::ListValue* key_ops, 143 const base::ListValue* key_ops,
167 blink::WebCryptoKeyUsageMask* usages); 144 blink::WebCryptoKeyUsageMask* usages);
168 145
169 } // namespace webcrypto 146 } // namespace webcrypto
170 147
171 #endif // COMPONENTS_WEBCRYPTO_JWK_H_ 148 #endif // COMPONENTS_WEBCRYPTO_JWK_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698