Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor for hax: avoid explicit return calls #150

Merged
merged 7 commits into from
Nov 21, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
refactor: remove unneeded trait for EdhocMessageBuffer
  • Loading branch information
geonnave committed Nov 20, 2023
commit 6601062baff32aa77a1118015e76822272d9e62f
22 changes: 6 additions & 16 deletions consts/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,6 @@ pub struct EdhocMessageBuffer {
pub len: usize,
}

impl EdhocMessageBuffer {}

impl Default for EdhocMessageBuffer {
fn default() -> Self {
EdhocMessageBuffer {
Expand All @@ -176,38 +174,30 @@ impl Default for EdhocMessageBuffer {
}
}

pub trait MessageBufferTrait {
fn new() -> Self;
fn get(self, index: usize) -> Option<u8>;
fn get_slice<'a>(&'a self, start: usize, len: usize) -> Option<&'a [u8]>;
fn as_slice<'a>(&'a self) -> &'a [u8];
fn from_hex(hex: &str) -> Self;
}

impl MessageBufferTrait for EdhocMessageBuffer {
fn new() -> Self {
impl EdhocMessageBuffer {
pub fn new() -> Self {
EdhocMessageBuffer {
content: [0u8; MAX_MESSAGE_SIZE_LEN],
len: 0,
}
}

fn get(self, index: usize) -> Option<u8> {
pub fn get(self, index: usize) -> Option<u8> {
match self.content.get(index) {
Some(b) => Some(*b),
_ => None,
}
}

fn get_slice<'a>(&'a self, start: usize, len: usize) -> Option<&'a [u8]> {
pub fn get_slice<'a>(&'a self, start: usize, len: usize) -> Option<&'a [u8]> {
self.content.get(start..len)
}

fn as_slice<'a>(&'a self) -> &'a [u8] {
pub fn as_slice<'a>(&'a self) -> &'a [u8] {
&self.content[0..self.len]
}

fn from_hex(hex: &str) -> Self {
pub fn from_hex(hex: &str) -> Self {
let mut buffer = EdhocMessageBuffer::new();
buffer.len = hex.len() / 2;
for (i, chunk) in hex.as_bytes().chunks(2).enumerate() {
Expand Down
2 changes: 1 addition & 1 deletion crypto/edhoc-crypto-rustcrypto/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use edhoc_consts::{
BufferCiphertext3, BufferPlaintext3, BytesCcmIvLen, BytesCcmKeyLen, BytesHashLen,
BytesMaxBuffer, BytesMaxInfoBuffer, BytesP256ElemLen, Crypto as CryptoTrait, EDHOCError,
MessageBufferTrait, AES_CCM_TAG_LEN, MAX_BUFFER_LEN,
AES_CCM_TAG_LEN, MAX_BUFFER_LEN,
};

use ccm::AeadInPlace;
Expand Down