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

Side by Side Diff: net/cert/jwk_serializer_nss.cc

Issue 22731002: Improve style of JWK serializer (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 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
« no previous file with comments | « no previous file | net/cert/jwk_serializer_openssl.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "net/cert/jwk_serializer.h" 5 #include "net/cert/jwk_serializer.h"
6 6
7 #include <cert.h> 7 #include <cert.h>
8 #include <keyhi.h> 8 #include <keyhi.h>
9 #include <nss.h> 9 #include <nss.h>
10 10
11 #include "base/base64.h" 11 #include "base/base64.h"
12 #include "base/values.h" 12 #include "base/values.h"
13 #include "crypto/nss_util.h" 13 #include "crypto/nss_util.h"
14 #include "crypto/scoped_nss_types.h" 14 #include "crypto/scoped_nss_types.h"
15 15
16 namespace net { 16 namespace net {
17 17
18 namespace JwkSerializer { 18 namespace JwkSerializer {
19 19
20 namespace { 20 namespace {
21 21
22 bool ConvertEcPrime256v1PublicKeyInfoToJwk( 22 bool ConvertEcPrime256v1PublicKeyInfoToJwk(
23 CERTSubjectPublicKeyInfo* spki, 23 CERTSubjectPublicKeyInfo* spki,
24 base::DictionaryValue* public_key_jwk) { 24 base::DictionaryValue* public_key_jwk) {
25 static const int kPrime256v1EncodingType = 4; 25 static const int kUncompressedEncodingType = 4;
26 static const int kPrime256v1PublicKeyLength = 64; 26 static const int kPrime256v1PublicKeyLength = 64;
27 // The public key value is encoded as 0x04 + 64 bytes of public key. 27 // The public key value is encoded as 0x04 + 64 bytes of public key.
28 // NSS gives the length as the bit length. 28 // NSS gives the length as the bit length.
29 if (spki->subjectPublicKey.len != (kPrime256v1PublicKeyLength + 1) * 8 || 29 if (spki->subjectPublicKey.len != (kPrime256v1PublicKeyLength + 1) * 8 ||
30 spki->subjectPublicKey.data[0] != kPrime256v1EncodingType) 30 spki->subjectPublicKey.data[0] != kUncompressedEncodingType)
31 return false; 31 return false;
32 32
33 public_key_jwk->SetString("alg", "EC"); 33 public_key_jwk->SetString("alg", "EC");
34 public_key_jwk->SetString("crv", "P-256"); 34 public_key_jwk->SetString("crv", "P-256");
35 35
36 base::StringPiece x( 36 base::StringPiece x(
37 reinterpret_cast<char*>(spki->subjectPublicKey.data + 1), 37 reinterpret_cast<char*>(spki->subjectPublicKey.data + 1),
38 kPrime256v1PublicKeyLength / 2); 38 kPrime256v1PublicKeyLength / 2);
39 std::string x_b64; 39 std::string x_b64;
40 base::Base64Encode(x, &x_b64); 40 base::Base64Encode(x, &x_b64);
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 sizeof(kIdEcPublicKey))) { 109 sizeof(kIdEcPublicKey))) {
110 rv = ConvertEcPublicKeyInfoToJwk(spki.get(), public_key_jwk); 110 rv = ConvertEcPublicKeyInfoToJwk(spki.get(), public_key_jwk);
111 } 111 }
112 // TODO(juanlang): other algorithms 112 // TODO(juanlang): other algorithms
113 return rv; 113 return rv;
114 } 114 }
115 115
116 } // namespace JwkSerializer 116 } // namespace JwkSerializer
117 117
118 } // namespace net 118 } // namespace net
OLDNEW
« no previous file with comments | « no previous file | net/cert/jwk_serializer_openssl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698