1*3f8e9d82SAndroid Build Coastguard Worker /* 2*3f8e9d82SAndroid Build Coastguard Worker * Copyright (C) 2023 The Android Open Source Project 3*3f8e9d82SAndroid Build Coastguard Worker * 4*3f8e9d82SAndroid Build Coastguard Worker * Licensed under the Apache License, Version 2.0 (the "License"); 5*3f8e9d82SAndroid Build Coastguard Worker * you may not use this file except in compliance with the License. 6*3f8e9d82SAndroid Build Coastguard Worker * You may obtain a copy of the License at 7*3f8e9d82SAndroid Build Coastguard Worker * 8*3f8e9d82SAndroid Build Coastguard Worker * http://www.apache.org/licenses/LICENSE-2.0 9*3f8e9d82SAndroid Build Coastguard Worker * 10*3f8e9d82SAndroid Build Coastguard Worker * Unless required by applicable law or agreed to in writing, software 11*3f8e9d82SAndroid Build Coastguard Worker * distributed under the License is distributed on an "AS IS" BASIS, 12*3f8e9d82SAndroid Build Coastguard Worker * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13*3f8e9d82SAndroid Build Coastguard Worker * See the License for the specific language governing permissions and 14*3f8e9d82SAndroid Build Coastguard Worker * limitations under the License. 15*3f8e9d82SAndroid Build Coastguard Worker */ 16*3f8e9d82SAndroid Build Coastguard Worker 17*3f8e9d82SAndroid Build Coastguard Worker //! Implements various useful CBOR conversion method. 18*3f8e9d82SAndroid Build Coastguard Worker 19*3f8e9d82SAndroid Build Coastguard Worker use crate::data_types::error::Error; 20*3f8e9d82SAndroid Build Coastguard Worker use ciborium::Value; 21*3f8e9d82SAndroid Build Coastguard Worker 22*3f8e9d82SAndroid Build Coastguard Worker // Useful to convert [`ciborium::Value`] to integer, we return largest integer range for 23*3f8e9d82SAndroid Build Coastguard Worker // convenience, callers should downcast into appropriate type. value_to_integer(value: &Value) -> Result<i128, Error>24*3f8e9d82SAndroid Build Coastguard Workerpub fn value_to_integer(value: &Value) -> Result<i128, Error> { 25*3f8e9d82SAndroid Build Coastguard Worker let num = value.as_integer().ok_or(Error::ConversionError)?.into(); 26*3f8e9d82SAndroid Build Coastguard Worker Ok(num) 27*3f8e9d82SAndroid Build Coastguard Worker } 28