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

Side by Side Diff: content/child/webcrypto/generate_key_result.cc

Issue 512023002: Refactor the interface for generating keys. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Run git-cl format Created 6 years, 2 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "content/child/webcrypto/generate_key_result.h"
6
7 #include "base/logging.h"
8
9 namespace content {
10
11 namespace webcrypto {
12
13 GenerateKeyResult::GenerateKeyResult()
14 : type_(TYPE_NULL),
15 secret_key_(blink::WebCryptoKey::createNull()),
16 public_key_(blink::WebCryptoKey::createNull()),
17 private_key_(blink::WebCryptoKey::createNull()) {
18 }
19
20 GenerateKeyResult::Type GenerateKeyResult::type() const {
21 return type_;
22 }
23
24 const blink::WebCryptoKey& GenerateKeyResult::secret_key() const {
25 DCHECK_EQ(TYPE_SECRET_KEY, type_);
26 return secret_key_;
27 }
28
29 const blink::WebCryptoKey& GenerateKeyResult::public_key() const {
30 DCHECK_EQ(TYPE_PUBLIC_PRIVATE_KEY_PAIR, type_);
31 return public_key_;
32 }
33
34 const blink::WebCryptoKey& GenerateKeyResult::private_key() const {
35 DCHECK_EQ(TYPE_PUBLIC_PRIVATE_KEY_PAIR, type_);
36 return private_key_;
37 }
38
39 void GenerateKeyResult::AssignSecretKey(const blink::WebCryptoKey& key) {
40 type_ = TYPE_SECRET_KEY;
41 secret_key_ = key;
42 }
43
44 void GenerateKeyResult::AssignKeyPair(const blink::WebCryptoKey& public_key,
45 const blink::WebCryptoKey& private_key) {
46 type_ = TYPE_PUBLIC_PRIVATE_KEY_PAIR;
47 public_key_ = public_key;
48 private_key_ = private_key;
49 }
50
51 void GenerateKeyResult::Complete(blink::WebCryptoResult* out) const {
52 switch (type_) {
53 case TYPE_NULL:
54 NOTREACHED();
55 break;
56 case TYPE_SECRET_KEY:
57 out->completeWithKey(secret_key());
58 break;
59 case TYPE_PUBLIC_PRIVATE_KEY_PAIR:
60 out->completeWithKeyPair(public_key(), private_key());
61 break;
62 }
63 }
64
65 } // namespace webcrypto
66
67 } // namespace content
OLDNEW
« no previous file with comments | « content/child/webcrypto/generate_key_result.h ('k') | content/child/webcrypto/nss/aes_gcm_nss.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698