[dice][refactor] Remove unused library libdiced_utils and tests
As all its callers have been migrated to the well maintained
crate ciborium in the previous cls (aosp/2459709, aosp/2462175),
we can now remove the library libdiced_utils safely.
Test: N/A.
Bug: 268322533
Change-Id: I91d014570a37782fdb3ec9ecdc9cb701c5374f4b
diff --git a/diced/Android.bp b/diced/Android.bp
index 3e15ed7..26a1c4d 100644
--- a/diced/Android.bp
+++ b/diced/Android.bp
@@ -22,26 +22,6 @@
}
rust_library {
- name: "libdiced_utils",
- crate_name: "diced_utils",
- srcs: ["src/utils.rs"],
- rustlibs: [
- "libanyhow",
- ],
-}
-
-rust_test {
- name: "diced_utils_test",
- crate_name: "diced_utils_test",
- srcs: ["src/utils.rs"],
- test_suites: ["general-tests"],
- auto_gen_config: true,
- rustlibs: [
- "libanyhow",
- ],
-}
-
-rust_library {
name: "libdiced_sample_inputs",
crate_name: "diced_sample_inputs",
srcs: ["src/sample_inputs.rs"],
diff --git a/diced/TEST_MAPPING b/diced/TEST_MAPPING
index 1b078a4..674b448 100644
--- a/diced/TEST_MAPPING
+++ b/diced/TEST_MAPPING
@@ -13,9 +13,6 @@
"name": "libopen_dice_bcc_bindgen_test"
},
{
- "name": "diced_utils_test"
- },
- {
"name": "diced_sample_inputs_test"
}
]
diff --git a/diced/src/utils.rs b/diced/src/utils.rs
deleted file mode 100644
index 0931e68..0000000
--- a/diced/src/utils.rs
+++ /dev/null
@@ -1,169 +0,0 @@
-// Copyright 2021, The Android Open Source Project
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-//! Implements utility functions and types for diced and the dice HAL.
-
-/// This submodule implements a limited set of CBOR generation functionality. Essentially,
-/// a cbor header generator and some convenience functions for number and BSTR encoding.
-pub mod cbor {
- use anyhow::{anyhow, Context, Result};
- use std::convert::TryInto;
- use std::io::Write;
-
- /// CBOR encodes a positive number.
- pub fn encode_number(n: u64, buffer: &mut dyn Write) -> Result<()> {
- encode_header(0, n, buffer)
- }
-
- /// CBOR encodes a binary string.
- pub fn encode_bstr(bstr: &[u8], buffer: &mut dyn Write) -> Result<()> {
- encode_header(
- 2,
- bstr.len().try_into().context("In encode_bstr: Failed to convert usize to u64.")?,
- buffer,
- )
- .context("In encode_bstr: While writing header.")?;
- let written = buffer.write(bstr).context("In encode_bstr: While writing payload.")?;
- if written != bstr.len() {
- return Err(anyhow!("In encode_bstr: Buffer too small. ({}, {})", written, bstr.len()));
- }
- Ok(())
- }
-
- /// Formats a CBOR header. `t` is the type, and n is the header argument.
- pub fn encode_header(t: u8, n: u64, buffer: &mut dyn Write) -> Result<()> {
- match n {
- n if n < 24 => {
- let written =
- buffer.write(&u8::to_be_bytes((t << 5) | (n as u8 & 0x1F))).with_context(
- || format!("In encode_header: Failed to write header ({}, {})", t, n),
- )?;
- if written != 1 {
- return Err(anyhow!("In encode_header: Buffer to small. ({}, {})", t, n));
- }
- }
- n if n <= 0xFF => {
- let written =
- buffer.write(&u8::to_be_bytes((t << 5) | (24u8 & 0x1F))).with_context(
- || format!("In encode_header: Failed to write header ({}, {})", t, n),
- )?;
- if written != 1 {
- return Err(anyhow!("In encode_header: Buffer to small. ({}, {})", t, n));
- }
- let written = buffer.write(&u8::to_be_bytes(n as u8)).with_context(|| {
- format!("In encode_header: Failed to write size ({}, {})", t, n)
- })?;
- if written != 1 {
- return Err(anyhow!(
- "In encode_header while writing size: Buffer to small. ({}, {})",
- t,
- n
- ));
- }
- }
- n if n <= 0xFFFF => {
- let written =
- buffer.write(&u8::to_be_bytes((t << 5) | (25u8 & 0x1F))).with_context(
- || format!("In encode_header: Failed to write header ({}, {})", t, n),
- )?;
- if written != 1 {
- return Err(anyhow!("In encode_header: Buffer to small. ({}, {})", t, n));
- }
- let written = buffer.write(&u16::to_be_bytes(n as u16)).with_context(|| {
- format!("In encode_header: Failed to write size ({}, {})", t, n)
- })?;
- if written != 2 {
- return Err(anyhow!(
- "In encode_header while writing size: Buffer to small. ({}, {})",
- t,
- n
- ));
- }
- }
- n if n <= 0xFFFFFFFF => {
- let written =
- buffer.write(&u8::to_be_bytes((t << 5) | (26u8 & 0x1F))).with_context(
- || format!("In encode_header: Failed to write header ({}, {})", t, n),
- )?;
- if written != 1 {
- return Err(anyhow!("In encode_header: Buffer to small. ({}, {})", t, n));
- }
- let written = buffer.write(&u32::to_be_bytes(n as u32)).with_context(|| {
- format!("In encode_header: Failed to write size ({}, {})", t, n)
- })?;
- if written != 4 {
- return Err(anyhow!(
- "In encode_header while writing size: Buffer to small. ({}, {})",
- t,
- n
- ));
- }
- }
- n => {
- let written =
- buffer.write(&u8::to_be_bytes((t << 5) | (27u8 & 0x1F))).with_context(
- || format!("In encode_header: Failed to write header ({}, {})", t, n),
- )?;
- if written != 1 {
- return Err(anyhow!("In encode_header: Buffer to small. ({}, {})", t, n));
- }
- let written = buffer.write(&u64::to_be_bytes(n)).with_context(|| {
- format!("In encode_header: Failed to write size ({}, {})", t, n)
- })?;
- if written != 8 {
- return Err(anyhow!(
- "In encode_header while writing size: Buffer to small. ({}, {})",
- t,
- n
- ));
- }
- }
- }
- Ok(())
- }
-
- #[cfg(test)]
- mod test {
- use super::*;
-
- fn encode_header_helper(t: u8, n: u64) -> Vec<u8> {
- let mut b: Vec<u8> = vec![];
- encode_header(t, n, &mut b).unwrap();
- b
- }
-
- #[test]
- fn encode_header_test() {
- assert_eq!(&encode_header_helper(0, 0), &[0b000_00000]);
- assert_eq!(&encode_header_helper(0, 23), &[0b000_10111]);
- assert_eq!(&encode_header_helper(0, 24), &[0b000_11000, 24]);
- assert_eq!(&encode_header_helper(0, 0xff), &[0b000_11000, 0xff]);
- assert_eq!(&encode_header_helper(0, 0x100), &[0b000_11001, 0x01, 0x00]);
- assert_eq!(&encode_header_helper(0, 0xffff), &[0b000_11001, 0xff, 0xff]);
- assert_eq!(&encode_header_helper(0, 0x10000), &[0b000_11010, 0x00, 0x01, 0x00, 0x00]);
- assert_eq!(
- &encode_header_helper(0, 0xffffffff),
- &[0b000_11010, 0xff, 0xff, 0xff, 0xff]
- );
- assert_eq!(
- &encode_header_helper(0, 0x100000000),
- &[0b000_11011, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00]
- );
- assert_eq!(
- &encode_header_helper(0, 0xffffffffffffffff),
- &[0b000_11011, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff]
- );
- }
- }
-}