Roll src/third_party/WebKit f36d5e0:68b67cd (svn 193299:193303)
[chromium-blink-merge.git] / content / child / webcrypto / generate_key_result.cc
blob3c61657eb55fc71c8fc2fc654073935268202bde
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.
5 #include "content/child/webcrypto/generate_key_result.h"
7 #include "base/logging.h"
9 namespace content {
11 namespace webcrypto {
13 GenerateKeyResult::GenerateKeyResult() : type_(TYPE_NULL) {
16 GenerateKeyResult::Type GenerateKeyResult::type() const {
17 return type_;
20 const blink::WebCryptoKey& GenerateKeyResult::secret_key() const {
21 DCHECK_EQ(TYPE_SECRET_KEY, type_);
22 return secret_key_;
25 const blink::WebCryptoKey& GenerateKeyResult::public_key() const {
26 DCHECK_EQ(TYPE_PUBLIC_PRIVATE_KEY_PAIR, type_);
27 return public_key_;
30 const blink::WebCryptoKey& GenerateKeyResult::private_key() const {
31 DCHECK_EQ(TYPE_PUBLIC_PRIVATE_KEY_PAIR, type_);
32 return private_key_;
35 void GenerateKeyResult::AssignSecretKey(const blink::WebCryptoKey& key) {
36 type_ = TYPE_SECRET_KEY;
37 secret_key_ = key;
40 void GenerateKeyResult::AssignKeyPair(const blink::WebCryptoKey& public_key,
41 const blink::WebCryptoKey& private_key) {
42 type_ = TYPE_PUBLIC_PRIVATE_KEY_PAIR;
43 public_key_ = public_key;
44 private_key_ = private_key;
47 void GenerateKeyResult::Complete(blink::WebCryptoResult* out) const {
48 switch (type_) {
49 case TYPE_NULL:
50 NOTREACHED();
51 break;
52 case TYPE_SECRET_KEY:
53 out->completeWithKey(secret_key());
54 break;
55 case TYPE_PUBLIC_PRIVATE_KEY_PAIR:
56 out->completeWithKeyPair(public_key(), private_key());
57 break;
61 } // namespace webcrypto
63 } // namespace content