Home | History | Annotate | Download | only in encoding
      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_SECRETENCODER_H_
     16 #define POLO_ENCODING_SECRETENCODER_H_
     17 
     18 #include <stdint.h>
     19 #include <string>
     20 #include <vector>
     21 
     22 namespace polo {
     23 namespace encoding {
     24 
     25 // Encodes and decodes secret challenges. The decoded secret is displayed to the
     26 // user on the display device, and entered by the user on the input device. The
     27 // secret is encoded for transmission on the wire and used for computing pairing
     28 // keys.
     29 class SecretEncoder {
     30  public:
     31   virtual ~SecretEncoder() {}
     32 
     33   // Encodes a byte array representation of a secret to a string.
     34   // @param secret the secret bytes
     35   // @return a string representation of the given secret
     36   virtual std::string EncodeToString(
     37       const std::vector<uint8_t>& secret) const = 0;
     38 
     39   // Decodes the string representation of the secret to a byte array.
     40   // @param secret a string representation of the secret
     41   // @return the decoded secret as a byte array
     42   virtual std::vector<uint8_t> DecodeToBytes(
     43       const std::string& secret) const = 0;
     44 
     45   // The number of symbols contained in each byte of data. For example, a
     46   // hexadecimal encoding has 4 bytes per symbol and therefore 2 symbols per
     47   // byte.
     48   virtual size_t symbols_per_byte() const = 0;
     49 };
     50 
     51 }  // namespace encoding
     52 }  // namespace polo
     53 
     54 #endif  // POLO_ENCODING_SECRETENCODER_H_
     55