1 // Copyright 2012 Google Inc. All Rights Reserved. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 #ifndef POLO_ENCODING_HEXADECIMALENCODER_H_ 16 #define POLO_ENCODING_HEXADECIMALENCODER_H_ 17 18 #include <string> 19 #include <vector> 20 21 #include "polo/encoding/secretencoder.h" 22 23 namespace polo { 24 namespace encoding { 25 26 // Encodes and decodes secret challenges as hexadecimal strings. 27 class HexadecimalEncoder : public SecretEncoder { 28 public: 29 // @override 30 virtual std::string EncodeToString( 31 const std::vector<uint8_t>& secret) const; 32 33 // @override 34 virtual std::vector<uint8_t> DecodeToBytes( 35 const std::string& secret) const; 36 37 // @override 38 virtual size_t symbols_per_byte() const;\ 39 private: 40 enum { 41 // Hex encoding has 2 symbols per byte since each hex character uses 4 bits. 42 HEX_SYMBOLS_PER_BYTE = 2 43 }; 44 }; 45 46 } // namespace encoding 47 } // namespace polo 48 49 #endif // POLO_ENCODING_HEXADECIMALENCODER_H_ 50