| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "crypto/openpgp_symmetric_encryption.h" | 5 #include "crypto/openpgp_symmetric_encryption.h" |
| 6 | 6 |
| 7 #include <stdlib.h> | 7 #include <stdlib.h> |
| 8 | 8 |
| 9 #include <sechash.h> | 9 #include <sechash.h> |
| 10 #include <cryptohi.h> | 10 #include <cryptohi.h> |
| 11 | 11 |
| 12 #include <vector> | 12 #include <vector> |
| 13 | 13 |
| 14 #include "base/logging.h" | 14 #include "base/logging.h" |
| 15 #include "crypto/random.h" | 15 #include "crypto/random.h" |
| 16 #include "crypto/scoped_nss_types.h" | 16 #include "crypto/scoped_nss_types.h" |
| 17 #include "crypto/nss_util.h" | 17 #include "crypto/nss_util.h" |
| 18 | 18 |
| 19 namespace crypto { | 19 namespace crypto { |
| 20 | 20 |
| 21 namespace { | 21 namespace { |
| 22 | 22 |
| 23 // Reader wraps a StringPiece and provides methods to read several datatypes | 23 // Reader wraps a StringPiece and provides methods to read several datatypes |
| 24 // while advancing the StringPiece. | 24 // while advancing the StringPiece. |
| 25 class Reader { | 25 class Reader { |
| 26 public: | 26 public: |
| 27 Reader(base::StringPiece input) | 27 explicit Reader(base::StringPiece input) |
| 28 : data_(input) { | 28 : data_(input) { |
| 29 } | 29 } |
| 30 | 30 |
| 31 bool U8(uint8* out) { | 31 bool U8(uint8* out) { |
| 32 if (data_.size() < 1) | 32 if (data_.size() < 1) |
| 33 return false; | 33 return false; |
| 34 *out = static_cast<uint8>(data_[0]); | 34 *out = static_cast<uint8>(data_[0]); |
| 35 data_.remove_prefix(1); | 35 data_.remove_prefix(1); |
| 36 return true; | 36 return true; |
| 37 } | 37 } |
| (...skipping 748 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 786 base::StringPiece plaintext, | 786 base::StringPiece plaintext, |
| 787 base::StringPiece passphrase) { | 787 base::StringPiece passphrase) { |
| 788 EnsureNSSInit(); | 788 EnsureNSSInit(); |
| 789 | 789 |
| 790 Encrypter::ByteString b = | 790 Encrypter::ByteString b = |
| 791 Encrypter::Encrypt(plaintext, passphrase); | 791 Encrypter::Encrypt(plaintext, passphrase); |
| 792 return std::string(reinterpret_cast<const char*>(b.data()), b.size()); | 792 return std::string(reinterpret_cast<const char*>(b.data()), b.size()); |
| 793 } | 793 } |
| 794 | 794 |
| 795 } // namespace crypto | 795 } // namespace crypto |
| OLD | NEW |