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 "components/webcrypto/generate_key_result.h"
7 #include "base/logging.h"
11 GenerateKeyResult::GenerateKeyResult() : type_(TYPE_NULL
) {
14 GenerateKeyResult::Type
GenerateKeyResult::type() const {
18 const blink::WebCryptoKey
& GenerateKeyResult::secret_key() const {
19 DCHECK_EQ(TYPE_SECRET_KEY
, type_
);
23 const blink::WebCryptoKey
& GenerateKeyResult::public_key() const {
24 DCHECK_EQ(TYPE_PUBLIC_PRIVATE_KEY_PAIR
, type_
);
28 const blink::WebCryptoKey
& GenerateKeyResult::private_key() const {
29 DCHECK_EQ(TYPE_PUBLIC_PRIVATE_KEY_PAIR
, type_
);
33 void GenerateKeyResult::AssignSecretKey(const blink::WebCryptoKey
& key
) {
34 type_
= TYPE_SECRET_KEY
;
38 void GenerateKeyResult::AssignKeyPair(const blink::WebCryptoKey
& public_key
,
39 const blink::WebCryptoKey
& private_key
) {
40 type_
= TYPE_PUBLIC_PRIVATE_KEY_PAIR
;
41 public_key_
= public_key
;
42 private_key_
= private_key
;
45 void GenerateKeyResult::Complete(blink::WebCryptoResult
* out
) const {
51 out
->completeWithKey(secret_key());
53 case TYPE_PUBLIC_PRIVATE_KEY_PAIR
:
54 out
->completeWithKeyPair(public_key(), private_key());
59 } // namespace webcrypto