Skip to content

Commit

Permalink
Move LABEL_SIG constant to a crate, so that it can be re-used. (#2006)
Browse files Browse the repository at this point in the history
  • Loading branch information
przydatek authored Nov 2, 2023
1 parent 7eb483d commit f3abe41
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/canister_sig_util/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ pub fn get_canister_sig_pk_der(canister_id: Principal, seed: &[u8]) -> Vec<u8> {
}

/// Verifies the structure given public key in DER-format, and returns raw bytes of the key.
fn extract_raw_root_pk_from_der(pk_der: &[u8]) -> Result<Vec<u8>, String> {
pub fn extract_raw_root_pk_from_der(pk_der: &[u8]) -> Result<Vec<u8>, String> {
let expected_length = IC_ROOT_PK_DER_PREFIX.len() + IC_ROOT_PK_LENGTH;
if pk_der.len() != expected_length {
return Err(String::from("invalid root pk length"));
Expand Down
1 change: 1 addition & 0 deletions src/canister_sig_util/src/signature_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use ic_certified_map::{leaf_hash, AsHashTree, Hash, HashTree, RbTree};
use std::borrow::Cow;
use std::collections::BinaryHeap;

pub const LABEL_SIG: &[u8] = b"sig";
#[derive(Default)]
struct Unit;

Expand Down
4 changes: 2 additions & 2 deletions src/internet_identity/src/delegation.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use crate::assets::CertifiedAssets;
use crate::ii_domain::IIDomain;
use crate::state::persistent_state_mut;
use crate::{hash, state, update_root_hash, DAY_NS, LABEL_SIG, MINUTE_NS};
use crate::{hash, state, update_root_hash, DAY_NS, MINUTE_NS};
use candid::Principal;
use canister_sig_util::get_canister_sig_pk_der;
use canister_sig_util::signature_map::SignatureMap;
use canister_sig_util::signature_map::{SignatureMap, LABEL_SIG};
use ic_cdk::api::{data_certificate, time};
use ic_cdk::{id, trap};
use ic_certified_map::{Hash, HashTree};
Expand Down
3 changes: 2 additions & 1 deletion src/internet_identity/src/http.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use crate::assets::{ContentType, EXACT_MATCH_TERMINATOR, IC_CERTIFICATE_EXPRESSION};
use crate::http::metrics::metrics;
use crate::{assets, state, LABEL_SIG};
use crate::{assets, state};
use base64::engine::general_purpose::STANDARD as BASE64;
use base64::Engine;
use canister_sig_util::signature_map::LABEL_SIG;
use ic_cdk::api::data_certificate;
use ic_cdk::trap;
use ic_certified_map::HashTree;
Expand Down
3 changes: 1 addition & 2 deletions src/internet_identity/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use crate::assets::init_assets;
use crate::ii_domain::IIDomain;
use crate::storage::anchor::Anchor;
use candid::{candid_method, Principal};
use canister_sig_util::signature_map::LABEL_SIG;
use ic_cdk::api::{caller, set_certified_data, trap};
use ic_cdk_macros::{init, post_upgrade, pre_upgrade, query, update};
use internet_identity_interface::archive::types::{BufferedEntry, Operation};
Expand Down Expand Up @@ -34,8 +35,6 @@ const MINUTE_NS: u64 = secs_to_nanos(60);
const HOUR_NS: u64 = 60 * MINUTE_NS;
const DAY_NS: u64 = 24 * HOUR_NS;

const LABEL_SIG: &[u8] = b"sig";

// Note: concatenating const &str is a hassle in rust. It seemed easiest to just repeat.
const IC0_APP_DOMAIN: &str = "identity.ic0.app";
const IC0_APP_ORIGIN: &str = "https://identity.ic0.app";
Expand Down

0 comments on commit f3abe41

Please sign in to comment.