pub fn create_log(
    ciphersuite: CipherSuite,
    admin_username: &str,
    admin_keypair: &KeyPair,
    admin_keypair_sealed: &[u8],
    admin_keypair_salt: &[u8],
    comment: &str,
) -> Block {
    // This is the only ciphersuite we presently support
    assert_eq!(ciphersuite, CipherSuite::Ed25519_AES256GCM_SHA256);

    let timestamp = Timestamp::now();

    let mut ops = Vec::new();
    let mut path = PathBuf::new();

    // Root DSE
    let mut root = Root::new();
    root.set_digest_alg(DigestAlg::SHA256);

    let mut root_object = Object::new();
    root_object.set_root(root);

    let mut root_op = Op::new();
    root_op.set_optype(op::Type::ADD);
    root_op.set_path(path.clone().into());
    root_op.set_object(root_object);
    ops.push(root_op);

    // Global Domain
    path.push("global");

    let mut global_domain = Domain::new();
    global_domain.set_description(String::from("Global system users and config"));

    let mut global_domain_object = Object::new();
    global_domain_object.set_domain(global_domain);

    let mut global_domain_op = Op::new();
    global_domain_op.set_optype(op::Type::ADD);
    global_domain_op.set_path(path.clone().into());
    global_domain_op.set_object(global_domain_object);
    ops.push(global_domain_op);

    // Users OU
    path.push("users");

    let mut global_users_ou = OrgUnit::new();
    global_users_ou.set_description(String::from("Core system users"));

    let mut global_users_object = Object::new();
    global_users_object.set_org_unit(global_users_ou);

    let mut global_users_op = Op::new();
    global_users_op.set_optype(op::Type::ADD);
    global_users_op.set_path(path.clone().into());
    global_users_op.set_object(global_users_object);
    ops.push(global_users_op);

    // Admin User
    path.push(&admin_username);

    let mut admin_user = System::new();
    admin_user.set_username(String::from(admin_username));

    let mut admin_user_object = Object::new();
    admin_user_object.set_system(admin_user);

    let mut admin_user_op = Op::new();
    admin_user_op.set_optype(op::Type::ADD);
    admin_user_op.set_path(path.clone().into());
    admin_user_op.set_object(admin_user_object);
    ops.push(admin_user_op);

    // Admin Credentials
    path.push("keys");

    let mut admin_keys_ou = OrgUnit::new();
    admin_keys_ou.set_description(String::from("Admin credentials"));

    let mut admin_keys_object = Object::new();
    admin_keys_object.set_org_unit(admin_keys_ou);

    let mut admin_keys_op = Op::new();
    admin_keys_op.set_optype(op::Type::ADD);
    admin_keys_op.set_path(path.clone().into());
    admin_keys_op.set_object(admin_keys_object);
    ops.push(admin_keys_op);

    // Admin Signature Key
    path.push("signing");

    // TODO: honor ciphersuite algorithms
    // TODO: keyid, credential_alg
    let mut admin_signing_credential = Credential::new();
    admin_signing_credential.set_credential_type(credential::Type::SIGNATURE_KEY_PAIR);
    admin_signing_credential.set_sealing_alg(EncryptionAlg::AES256GCM);
    admin_signing_credential.set_encrypted_value(Vec::from(admin_keypair_sealed));
    admin_signing_credential.set_salt(Vec::from(admin_keypair_salt));
    admin_signing_credential.set_public_key(Vec::from(admin_keypair.public_key_bytes()));
    admin_signing_credential.set_not_before(timestamp.to_int());
    admin_signing_credential.set_not_after(timestamp.extend(ADMIN_KEYPAIR_LIFETIME).to_int());
    admin_signing_credential.set_description(String::from("Root signing key"));

    let mut admin_signing_credential_object = Object::new();
    admin_signing_credential_object.set_credential(admin_signing_credential);

    let mut admin_signing_credential_op = Op::new();
    admin_signing_credential_op.set_optype(op::Type::ADD);
    admin_signing_credential_op.set_path(path.into());
    admin_signing_credential_op.set_object(admin_signing_credential_object);
    ops.push(admin_signing_credential_op);

    let mut body = Body::new();
    body.set_parent_id(Vec::from(BlockId::zero().as_ref()));
    body.set_timestamp(timestamp.to_int());
    body.set_ops(RepeatedField::from_vec(ops));
    body.set_comment(comment.to_owned());

    admin_keypair.sign_block(body)
}
/// Create the first block in a new log, with a parent ID of zero.
///
/// This block contains the initial administrative signature key which will
/// be used as the initial root authority for new blocks in the log.
///
/// The block is self-signed with the initial administrator key.
///
// TODO: Refactor this mess or create a policy language for these tasks instead
Create the first block in a new log, with a parent ID of zero.
This block contains the initial administrative signature key which will
be used as the initial root authority for new blocks in the log.

The block is self-signed with the initial administrator key.

Refactor this mess or create a policy language for these tasks instead
Create the first block in a new log with a parent ID of zero . This block contains the initial administrative signature key which will be used as the initial root authority for new blocks in the log . The block is self - signed with the initial administrator key . Refactor this mess or create a policy language for these tasks instead
pub fn create_log(
    ciphersuite: CipherSuite,
    admin_username: &str,
    admin_keypair: &KeyPair,
    admin_keypair_sealed: &[u8],
    admin_keypair_salt: &[u8],
    comment: &str,
) -> Block {
    // This is the only ciphersuite we presently support
    assert_eq!(ciphersuite, CipherSuite::Ed25519_AES256GCM_SHA256);
    let timestamp = Timestamp::now();
    let mut ops = Vec::new();
    let mut path = PathBuf::new();
    // Root DSE
    let mut root = Root::new();
    root.set_digest_alg(DigestAlg::SHA256);
    let mut root_object = Object::new();
    root_object.set_root(root);
    let mut root_op = Op::new();
    root_op.set_optype(op::Type::ADD);
    root_op.set_path(path.clone().into());
    root_op.set_object(root_object);
    ops.push(root_op);
    // Global Domain
    path.push("global");
    let mut global_domain = Domain::new();
    global_domain.set_description(String::from("Global system users and config"));
    let mut global_domain_object = Object::new();
    global_domain_object.set_domain(global_domain);
    let mut global_domain_op = Op::new();
    global_domain_op.set_optype(op::Type::ADD);
    global_domain_op.set_path(path.clone().into());
    global_domain_op.set_object(global_domain_object);
    ops.push(global_domain_op);
    // Users OU
    path.push("users");
    let mut global_users_ou = OrgUnit::new();
    global_users_ou.set_description(String::from("Core system users"));
    let mut global_users_object = Object::new();
    global_users_object.set_org_unit(global_users_ou);
    let mut global_users_op = Op::new();
    global_users_op.set_optype(op::Type::ADD);
    global_users_op.set_path(path.clone().into());
    global_users_op.set_object(global_users_object);
    ops.push(global_users_op);
    // Admin User
    path.push(&admin_username);
    let mut admin_user = System::new();
    admin_user.set_username(String::from(admin_username));
    let mut admin_user_object = Object::new();
    admin_user_object.set_system(admin_user);
    let mut admin_user_op = Op::new();
    admin_user_op.set_optype(op::Type::ADD);
    admin_user_op.set_path(path.clone().into());
    admin_user_op.set_object(admin_user_object);
    ops.push(admin_user_op);
    // Admin Credentials
    path.push("keys");
    let mut admin_keys_ou = OrgUnit::new();
    admin_keys_ou.set_description(String::from("Admin credentials"));
    let mut admin_keys_object = Object::new();
    admin_keys_object.set_org_unit(admin_keys_ou);
    let mut admin_keys_op = Op::new();
    admin_keys_op.set_optype(op::Type::ADD);
    admin_keys_op.set_path(path.clone().into());
    admin_keys_op.set_object(admin_keys_object);
    ops.push(admin_keys_op);
    // Admin Signature Key
    path.push("signing");
    // TODO: honor ciphersuite algorithms
    // TODO: keyid, credential_alg
    let mut admin_signing_credential = Credential::new();
    admin_signing_credential.set_credential_type(credential::Type::SIGNATURE_KEY_PAIR);
    admin_signing_credential.set_sealing_alg(EncryptionAlg::AES256GCM);
    admin_signing_credential.set_encrypted_value(Vec::from(admin_keypair_sealed));
    admin_signing_credential.set_salt(Vec::from(admin_keypair_salt));
    admin_signing_credential.set_public_key(Vec::from(admin_keypair.public_key_bytes()));
    admin_signing_credential.set_not_before(timestamp.to_int());
    admin_signing_credential.set_not_after(timestamp.extend(ADMIN_KEYPAIR_LIFETIME).to_int());
    admin_signing_credential.set_description(String::from("Root signing key"));
    let mut admin_signing_credential_object = Object::new();
    admin_signing_credential_object.set_credential(admin_signing_credential);
    let mut admin_signing_credential_op = Op::new();
    admin_signing_credential_op.set_optype(op::Type::ADD);
    admin_signing_credential_op.set_path(path.into());
    admin_signing_credential_op.set_object(admin_signing_credential_object);
    ops.push(admin_signing_credential_op);
    let mut body = Body::new();
    body.set_parent_id(Vec::from(BlockId::zero().as_ref()));
    body.set_timestamp(timestamp.to_int());
    body.set_ops(RepeatedField::from_vec(ops));
    body.set_comment(comment.to_owned());
    admin_keypair.sign_block(body)
}
pub fn create_log ( ciphersuite : CipherSuite , admin_username : & str , admin_keypair : & KeyPair , admin_keypair_sealed : & [ u8 ] , admin_keypair_salt : & [ u8 ] , comment : & str , ) -> Block { // This is the only ciphersuite we presently support assert_eq ! ( ciphersuite CipherSuite Ed25519_AES256GCM_SHA256 ) ; let timestamp = Timestamp :: now ( ) ; let mut ops = Vec :: new ( ) ; let mut path = PathBuf :: new ( ) ; // Root DSE let mut root = Root :: new ( ) ; root . set_digest_alg ( DigestAlg :: SHA256 ) ; let mut root_object = Object :: new ( ) ; root_object . set_root ( root ) ; let mut root_op = Op :: new ( ) ; root_op . set_optype ( op :: Type :: ADD ) ; root_op . set_path ( path . clone ( ) . into ( ) ) ; root_op . set_object ( root_object ) ; ops . push ( root_op ) ; // Global Domain path . push ( " " ) ; let mut global_domain = Domain :: new ( ) ; global_domain . set_description ( String :: from ( " " ) ) ; let mut global_domain_object = Object :: new ( ) ; global_domain_object . set_domain ( global_domain ) ; let mut global_domain_op = Op :: new ( ) ; global_domain_op . set_optype ( op :: Type :: ADD ) ; global_domain_op . set_path ( path . clone ( ) . into ( ) ) ; global_domain_op . set_object ( global_domain_object ) ; ops . push ( global_domain_op ) ; // Users OU path . push ( " " ) ; let mut global_users_ou = OrgUnit :: new ( ) ; global_users_ou . set_description ( String :: from ( " " ) ) ; let mut global_users_object = Object :: new ( ) ; global_users_object . set_org_unit ( global_users_ou ) ; let mut global_users_op = Op :: new ( ) ; global_users_op . set_optype ( op :: Type :: ADD ) ; global_users_op . set_path ( path . clone ( ) . into ( ) ) ; global_users_op . set_object ( global_users_object ) ; ops . push ( global_users_op ) ; // Admin User path . push ( & admin_username ) ; let mut admin_user = System :: new ( ) ; admin_user . set_username ( String :: from ( admin_username ) ) ; let mut admin_user_object = Object :: new ( ) ; admin_user_object . set_system ( admin_user ) ; let mut admin_user_op = Op :: new ( ) ; admin_user_op . set_optype ( op :: Type :: ADD ) ; admin_user_op . set_path ( path . clone ( ) . into ( ) ) ; admin_user_op . set_object ( admin_user_object ) ; ops . push ( admin_user_op ) ; // Admin Credentials path . push ( " " ) ; let mut admin_keys_ou = OrgUnit :: new ( ) ; admin_keys_ou . set_description ( String :: from ( " " ) ) ; let mut admin_keys_object = Object :: new ( ) ; admin_keys_object . set_org_unit ( admin_keys_ou ) ; let mut admin_keys_op = Op :: new ( ) ; admin_keys_op . set_optype ( op :: Type :: ADD ) ; admin_keys_op . set_path ( path . clone ( ) . into ( ) ) ; admin_keys_op . set_object ( admin_keys_object ) ; ops . push ( admin_keys_op ) ; // Admin Signature Key path . push ( " " ) ; // TODO: honor ciphersuite algorithms // TODO: keyid, credential_alg let mut admin_signing_credential = Credential :: new ( ) ; admin_signing_credential . set_credential_type ( credential :: Type :: SIGNATURE_KEY_PAIR ) ; admin_signing_credential . set_sealing_alg ( EncryptionAlg :: AES256GCM ) ; admin_signing_credential . set_encrypted_value ( Vec :: from ( admin_keypair_sealed ) ) ; admin_signing_credential . set_salt ( Vec :: from ( admin_keypair_salt ) ) ; admin_signing_credential . set_public_key ( Vec :: from ( admin_keypair . public_key_bytes ( ) ) ) ; admin_signing_credential . set_not_before ( timestamp . to_int ( ) ) ; admin_signing_credential . set_not_after ( timestamp . extend ( ADMIN_KEYPAIR_LIFETIME ) . to_int ( ) ) ; admin_signing_credential . set_description ( String :: from ( " " ) ) ; let mut admin_signing_credential_object = Object :: new ( ) ; admin_signing_credential_object . set_credential ( admin_signing_credential ) ; let mut admin_signing_credential_op = Op :: new ( ) ; admin_signing_credential_op . set_optype ( op :: Type :: ADD ) ; admin_signing_credential_op . set_path ( path . into ( ) ) ; admin_signing_credential_op . set_object ( admin_signing_credential_object ) ; ops . push ( admin_signing_credential_op ) ; let mut body = Body :: new ( ) ; body . set_parent_id ( Vec :: from ( BlockId :: zero ( ) . as_ref ( ) ) ) ; body . set_timestamp ( timestamp . to_int ( ) ) ; body . set_ops ( RepeatedField :: from_vec ( ops ) ) ; body . set_comment ( comment . to_owned ( ) ) ; admin_keypair . sign_block ( body ) }
Create the first block in a new log, with a parent ID of zero.
Create the first block in a new log with a parent ID of zero .
ciphersuite
CipherSuite
admin_username
&str
admin_keypair
&KeyPair
admin_keypair_sealed
&[u8]
admin_keypair_salt
&[u8]
comment
&str
ciphersuite
CipherSuite
admin_username
&str
admin_keypair
&KeyPair
admin_keypair_sealed
&[u8]
admin_keypair_salt
&[u8]
comment
&str