Vectorize website settings icons in omnibox
[chromium-blink-merge.git] / components / webcrypto / generate_key_result.cc
blob3c0c4e856926434f49e881c63df444abdad12f62
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"
9 namespace webcrypto {
11 GenerateKeyResult::GenerateKeyResult() : type_(TYPE_NULL) {
14 GenerateKeyResult::Type GenerateKeyResult::type() const {
15 return type_;
18 const blink::WebCryptoKey& GenerateKeyResult::secret_key() const {
19 DCHECK_EQ(TYPE_SECRET_KEY, type_);
20 return secret_key_;
23 const blink::WebCryptoKey& GenerateKeyResult::public_key() const {
24 DCHECK_EQ(TYPE_PUBLIC_PRIVATE_KEY_PAIR, type_);
25 return public_key_;
28 const blink::WebCryptoKey& GenerateKeyResult::private_key() const {
29 DCHECK_EQ(TYPE_PUBLIC_PRIVATE_KEY_PAIR, type_);
30 return private_key_;
33 void GenerateKeyResult::AssignSecretKey(const blink::WebCryptoKey& key) {
34 type_ = TYPE_SECRET_KEY;
35 secret_key_ = 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 {
46 switch (type_) {
47 case TYPE_NULL:
48 NOTREACHED();
49 break;
50 case TYPE_SECRET_KEY:
51 out->completeWithKey(secret_key());
52 break;
53 case TYPE_PUBLIC_PRIVATE_KEY_PAIR:
54 out->completeWithKeyPair(public_key(), private_key());
55 break;
59 } // namespace webcrypto