Skip to content

Commit

Permalink
chore: use ic-certification instead of ic-certified-map in asset cani…
Browse files Browse the repository at this point in the history
…ster (#3451)

`ic-certification` is now a strict upgrade of `ic-certified-map` and will be maintained in the future
  • Loading branch information
sesi200 authored Nov 20, 2023
1 parent 4c712a4 commit 7b6167c
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 49 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ Defining a custom `etag` header no longer breaks certification.

Fixed a certification issue where under certain conditions the fallback file (`/index.html`) was served with an incomplete certificate tree, not proving sufficiently that the fallback file may be used as a replacement.

- Module hash: 965c8899f0a033593dc9b1634b2ab4e0f3fd28c1cfa06993069be2040a2f700e
- Module hash: 1621e9ead6463304ceb3a81b10577c61c9d24f6e70b2e275a10b3a9be982dfb4
- https://github.com/dfinity/sdk/pull/3451
- https://github.com/dfinity/sdk/pull/3429
- https://github.com/dfinity/sdk/pull/3428
- https://github.com/dfinity/sdk/pull/3421
Expand Down
10 changes: 5 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/canisters/frontend/ic-certified-assets/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ base64.workspace = true
candid.workspace = true
hex.workspace = true
ic-cdk.workspace = true
ic-certified-map = "0.3.2"
ic-certification = "1.3.0"
ic-response-verification = "0.3.0"
ic-representation-independent-hash = "0.3.0"
itertools.workspace = true
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use self::{
tree::{merge_hash_trees, NestedTree},
tree::NestedTree,
types::{
certification::{AssetPath, HashTreePath, NestedTreeKey, RequestHash, WitnessResult},
http::{
Expand All @@ -8,13 +8,14 @@ use self::{
},
};
use crate::asset_certification::types::http::build_ic_certificate_expression_header;
use ic_certification::merge_hash_trees;
use ic_representation_independent_hash::Value;
use serde::Serialize;
use sha2::Digest;

pub mod tree;
pub mod types;
pub use ic_certified_map::HashTree;
pub use ic_certification::HashTree;

pub type CertifiedResponses = NestedTree<NestedTreeKey, Vec<u8>>;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use ic_certified_map::{AsHashTree, HashTree, RbTree};
use ic_certification::{AsHashTree, HashTree, RbTree};

pub trait NestedTreeKeyRequirements: Clone + AsRef<[u8]> + 'static {}
pub trait NestedTreeValueRequirements: AsHashTree + 'static {}
Expand All @@ -18,14 +18,14 @@ impl<K: NestedTreeKeyRequirements, V: NestedTreeValueRequirements> Default for N
}

impl<K: NestedTreeKeyRequirements, V: NestedTreeValueRequirements> AsHashTree for NestedTree<K, V> {
fn root_hash(&self) -> ic_certified_map::Hash {
fn root_hash(&self) -> ic_certification::Hash {
match self {
NestedTree::Leaf(a) => a.root_hash(),
NestedTree::Nested(tree) => tree.root_hash(),
}
}

fn as_hash_tree(&self) -> HashTree<'_> {
fn as_hash_tree(&self) -> HashTree {
match self {
NestedTree::Leaf(a) => a.as_hash_tree(),
NestedTree::Nested(tree) => tree.as_hash_tree(),
Expand Down Expand Up @@ -129,41 +129,6 @@ impl<K: NestedTreeKeyRequirements, V: NestedTreeValueRequirements> NestedTree<K,
}
}

pub fn merge_hash_trees<'a>(lhs: HashTree<'a>, rhs: HashTree<'a>) -> HashTree<'a> {
use HashTree::{Empty, Fork, Labeled, Leaf, Pruned};

match (lhs, rhs) {
(Pruned(l), Pruned(r)) => {
if l != r {
panic!("merge_hash_trees: inconsistent hashes");
}
Pruned(l)
}
(Pruned(_), r) => r,
(l, Pruned(_)) => l,
(Fork(l), Fork(r)) => Fork(Box::new((
merge_hash_trees(l.0, r.0),
merge_hash_trees(l.1, r.1),
))),
(Labeled(l_label, l), Labeled(r_label, r)) => {
if l_label != r_label {
panic!("merge_hash_trees: inconsistent hash tree labels");
}
Labeled(l_label, Box::new(merge_hash_trees(*l, *r)))
}
(Empty, Empty) => Empty,
(Leaf(l), Leaf(r)) => {
if l != r {
panic!("merge_hash_trees: inconsistent leaves");
}
Leaf(l)
}
(_l, _r) => {
panic!("merge_hash_trees: inconsistent tree structure");
}
}
}

#[test]
fn nested_tree_operation() {
let mut tree: NestedTree<&str, Vec<u8>> = NestedTree::default();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::{
state_machine::{encoding_certification_order, Asset, AssetEncoding},
};
use candid::{define_function, CandidType, Deserialize, Nat};
use ic_certified_map::Hash;
use ic_certification::Hash;
use ic_representation_independent_hash::{representation_independent_hash, Value};
use serde_bytes::ByteBuf;
use sha2::Digest;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use crate::{
url_decode::url_decode,
};
use candid::{CandidType, Deserialize, Int, Nat, Principal};
use ic_certified_map::{AsHashTree, Hash};
use ic_certification::{AsHashTree, Hash};
use ic_representation_independent_hash::Value;
use num_traits::ToPrimitive;
use serde::Serialize;
Expand Down
Binary file modified src/distributed/assetstorage.wasm.gz
Binary file not shown.

0 comments on commit 7b6167c

Please sign in to comment.