1 // Copyright 2017 Google Inc. 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 /////////////////////////////////////////////////////////////////////////////// 16 17 #ifndef TINK_CRYPTO_FORMAT_H_ 18 #define TINK_CRYPTO_FORMAT_H_ 19 20 #include <string> 21 #include <vector> 22 23 #include "tink/util/statusor.h" 24 #include "proto/tink.pb.h" 25 26 namespace crypto { 27 namespace tink { 28 29 // Constants and convenience methods that deal with the format 30 // of the outputs handled by Tink. 31 class CryptoFormat { 32 public: 33 // Prefix size of Tink and Legacy key types. 34 static constexpr int kNonRawPrefixSize = 5; 35 36 // Legacy prefix starts with \x00 and followed by a 4-byte key id. 37 static constexpr int kLegacyPrefixSize = kNonRawPrefixSize; 38 static constexpr uint8_t kLegacyStartByte = 0x00; 39 40 // Tink prefix starts with \x01 and followed by a 4-byte key id. 41 static constexpr int kTinkPrefixSize = kNonRawPrefixSize; 42 static constexpr uint8_t kTinkStartByte = 0x01; 43 44 // Raw prefix is empty. 45 static constexpr int kRawPrefixSize = 0; 46 static const absl::string_view kRawPrefix; // empty string 47 48 // Generates the prefix for the outputs handled with the given key_info. 49 // Returns an error if the prefix type 'output_prefix_type' is invalid. 50 static crypto::tink::util::StatusOr<std::string> GetOutputPrefix( 51 const google::crypto::tink::KeysetInfo::KeyInfo& key_info); 52 }; 53 54 } // namespace tink 55 } // namespace crypto 56 57 #endif // TINK_CRYPTO_FORMAT_H_ 58