| OLD | NEW |
| (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() : type_(TYPE_NULL) { | |
| 14 } | |
| 15 | |
| 16 GenerateKeyResult::Type GenerateKeyResult::type() const { | |
| 17 return type_; | |
| 18 } | |
| 19 | |
| 20 const blink::WebCryptoKey& GenerateKeyResult::secret_key() const { | |
| 21 DCHECK_EQ(TYPE_SECRET_KEY, type_); | |
| 22 return secret_key_; | |
| 23 } | |
| 24 | |
| 25 const blink::WebCryptoKey& GenerateKeyResult::public_key() const { | |
| 26 DCHECK_EQ(TYPE_PUBLIC_PRIVATE_KEY_PAIR, type_); | |
| 27 return public_key_; | |
| 28 } | |
| 29 | |
| 30 const blink::WebCryptoKey& GenerateKeyResult::private_key() const { | |
| 31 DCHECK_EQ(TYPE_PUBLIC_PRIVATE_KEY_PAIR, type_); | |
| 32 return private_key_; | |
| 33 } | |
| 34 | |
| 35 void GenerateKeyResult::AssignSecretKey(const blink::WebCryptoKey& key) { | |
| 36 type_ = TYPE_SECRET_KEY; | |
| 37 secret_key_ = key; | |
| 38 } | |
| 39 | |
| 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; | |
| 45 } | |
| 46 | |
| 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; | |
| 58 } | |
| 59 } | |
| 60 | |
| 61 } // namespace webcrypto | |
| 62 | |
| 63 } // namespace content | |
| OLD | NEW |