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"
13 GenerateKeyResult::GenerateKeyResult() : type_(TYPE_NULL) {
16 GenerateKeyResult::Type GenerateKeyResult::type() const {
20 const blink::WebCryptoKey& GenerateKeyResult::secret_key() const {
21 DCHECK_EQ(TYPE_SECRET_KEY, type_);
25 const blink::WebCryptoKey& GenerateKeyResult::public_key() const {
26 DCHECK_EQ(TYPE_PUBLIC_PRIVATE_KEY_PAIR, type_);
30 const blink::WebCryptoKey& GenerateKeyResult::private_key() const {
31 DCHECK_EQ(TYPE_PUBLIC_PRIVATE_KEY_PAIR, type_);
35 void GenerateKeyResult::AssignSecretKey(const blink::WebCryptoKey& key) {
36 type_ = TYPE_SECRET_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 {
53 out->completeWithKey(secret_key());
55 case TYPE_PUBLIC_PRIVATE_KEY_PAIR:
56 out->completeWithKeyPair(public_key(), private_key());
61 } // namespace webcrypto
63 } // namespace content