OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #ifndef CRYPTO_OPENPGP_SYMMETRIC_ENCRYPTION_H_ | 5 #ifndef CRYPTO_OPENPGP_SYMMETRIC_ENCRYPTION_H_ |
6 #define CRYPTO_OPENPGP_SYMMETRIC_ENCRYPTION_H_ | 6 #define CRYPTO_OPENPGP_SYMMETRIC_ENCRYPTION_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/string_piece.h" | 11 #include "base/string_piece.h" |
12 #include "crypto/crypto_api.h" | 12 #include "crypto/crypto_export.h" |
13 | 13 |
14 namespace crypto { | 14 namespace crypto { |
15 | 15 |
16 // OpenPGPSymmetricEncrytion implements enough of RFC 4880 to read and write | 16 // OpenPGPSymmetricEncrytion implements enough of RFC 4880 to read and write |
17 // uncompressed, symmetrically encrypted data. You can create ciphertext | 17 // uncompressed, symmetrically encrypted data. You can create ciphertext |
18 // compatable with this code from the command line with: | 18 // compatable with this code from the command line with: |
19 // gpg --compress-algo=NONE --cipher-algo=AES -c | 19 // gpg --compress-algo=NONE --cipher-algo=AES -c |
20 // | 20 // |
21 // Likewise, the output of this can be decrypted on the command line with: | 21 // Likewise, the output of this can be decrypted on the command line with: |
22 // gpg < input | 22 // gpg < input |
23 class CRYPTO_API OpenPGPSymmetricEncrytion { | 23 class CRYPTO_EXPORT OpenPGPSymmetricEncrytion { |
24 public: | 24 public: |
25 enum Result { | 25 enum Result { |
26 OK, | 26 OK, |
27 UNKNOWN_CIPHER, // you forgot to pass --cipher-algo=AES to gpg | 27 UNKNOWN_CIPHER, // you forgot to pass --cipher-algo=AES to gpg |
28 UNKNOWN_HASH, | 28 UNKNOWN_HASH, |
29 NOT_SYMMETRICALLY_ENCRYPTED, // it's OpenPGP data, but not correct form | 29 NOT_SYMMETRICALLY_ENCRYPTED, // it's OpenPGP data, but not correct form |
30 COMPRESSED, // you forgot to pass --compress-algo=NONE | 30 COMPRESSED, // you forgot to pass --compress-algo=NONE |
31 PARSE_ERROR, // it's not OpenPGP data. | 31 PARSE_ERROR, // it's not OpenPGP data. |
32 INTERNAL_ERROR, | 32 INTERNAL_ERROR, |
33 }; | 33 }; |
34 | 34 |
35 static Result Decrypt(base::StringPiece encrypted, | 35 static Result Decrypt(base::StringPiece encrypted, |
36 base::StringPiece passphrase, | 36 base::StringPiece passphrase, |
37 std::string *out); | 37 std::string *out); |
38 | 38 |
39 static std::string Encrypt(base::StringPiece plaintext, | 39 static std::string Encrypt(base::StringPiece plaintext, |
40 base::StringPiece passphrase); | 40 base::StringPiece passphrase); |
41 }; | 41 }; |
42 | 42 |
43 } // namespace crypto | 43 } // namespace crypto |
44 | 44 |
45 #endif // CRYPTO_OPENPGP_SYMMETRIC_ENCRYPTION_H_ | 45 #endif // CRYPTO_OPENPGP_SYMMETRIC_ENCRYPTION_H_ |
46 | 46 |
OLD | NEW |