1 /* 2 * Copyright (C) 2020 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #pragma once 18 19 #include <iostream> 20 #include <vector> 21 22 #include <aidl/android/hardware/security/keymint/Algorithm.h> 23 #include <aidl/android/hardware/security/keymint/BlockMode.h> 24 #include <aidl/android/hardware/security/keymint/Digest.h> 25 #include <aidl/android/hardware/security/keymint/EcCurve.h> 26 #include <aidl/android/hardware/security/keymint/ErrorCode.h> 27 #include <aidl/android/hardware/security/keymint/HardwareAuthenticatorType.h> 28 #include <aidl/android/hardware/security/keymint/KeyCharacteristics.h> 29 #include <aidl/android/hardware/security/keymint/KeyOrigin.h> 30 #include <aidl/android/hardware/security/keymint/KeyParameter.h> 31 #include <aidl/android/hardware/security/keymint/KeyPurpose.h> 32 #include <aidl/android/hardware/security/keymint/PaddingMode.h> 33 #include <aidl/android/hardware/security/keymint/SecurityLevel.h> 34 #include <aidl/android/hardware/security/keymint/Tag.h> 35 #include <aidl/android/hardware/security/keymint/TagType.h> 36 37 #include "keymint_tags.h" 38 39 namespace aidl::android::hardware::security::keymint { 40 41 inline ::std::ostream& operator<<(::std::ostream& os, Algorithm value) { 42 return os << toString(value); 43 } 44 45 inline ::std::ostream& operator<<(::std::ostream& os, BlockMode value) { 46 return os << toString(value); 47 } 48 49 inline ::std::ostream& operator<<(::std::ostream& os, Digest value) { 50 return os << toString(value); 51 } 52 53 inline ::std::ostream& operator<<(::std::ostream& os, EcCurve value) { 54 return os << toString(value); 55 } 56 57 inline ::std::ostream& operator<<(::std::ostream& os, ErrorCode value) { 58 return os << toString(value); 59 } 60 61 inline ::std::ostream& operator<<(::std::ostream& os, KeyOrigin value) { 62 return os << toString(value); 63 } 64 65 inline ::std::ostream& operator<<(::std::ostream& os, PaddingMode value) { 66 return os << toString(value); 67 } 68 69 inline ::std::ostream& operator<<(::std::ostream& os, SecurityLevel value) { 70 return os << toString(value); 71 } 72 73 template <typename ValueT> 74 ::std::ostream& operator<<(::std::ostream& os, const std::optional<ValueT>& value) { 75 if (!value.isOk()) { 76 os << "(value not present)"; 77 } else { 78 os << value.value(); 79 } 80 return os; 81 } 82 83 ::std::ostream& operator<<(::std::ostream& os, const ::std::vector<KeyParameter>& set); 84 ::std::ostream& operator<<(::std::ostream& os, const KeyParameter& param); 85 86 inline ::std::ostream& operator<<(::std::ostream& os, const KeyCharacteristics& value) { 87 for (auto& entry : value.authorizations) { 88 os << value.securityLevel << ": " << entry; 89 } 90 return os; 91 } 92 93 inline ::std::ostream& operator<<(::std::ostream& os, KeyPurpose value) { 94 return os << toString(value); 95 } 96 97 inline ::std::ostream& operator<<(::std::ostream& os, Tag tag) { 98 return os << toString(tag); 99 } 100 101 } // namespace aidl::android::hardware::security::keymint 102