Eine aufbereitete Darstellung der Quelle

 
     
 
 
Anforderungen  |   Konzepte  |   Entwurf  |   Entwicklung  |   Qualitätssicherung  |   Lebenszyklus  |   Steuerung
 
 
 
 

Benutzer

Quelle  identity_create.rs   Sprache: Rust

 

//! Example for creating a new Threema ID.
#![expect(unused_crate_dependencies, reason = "Example triggered false positive")]
#![expect(clippy::print_stdout, reason = "Examples are allowed to print")]

use clap::{ArgAction, Parser};
use libthreema::{
    cli::config::{CommonConfig, CommonConfigOptions},
    common::ClientInfo,
    csp_e2e::identity::create::{
        CreateIdentityContext, CreateIdentityLoop, CreateIdentityResponse, CreateIdentityResult,
        CreateIdentityTask,
    },
    https::cli::https_client_builder,
    utils::logging::init_stderr_logging,
};
use libthreema_dependencies::data_encoding::HEXLOWER_PERMISSIVE;
use tracing::Level;

#[derive(Parser)]
#[command()]
struct CreateIdentityCommand {
    #[command(flatten)]
    config: CommonConfigOptions,

    /// Turn on debugging information.
    /// Use -v -vv to control log level.
    #[arg(short, action = ArgAction::Count)]
    verbose: u8,
}

async fn run_create_identity(
    http_client: reqwest::Client,
    context: CreateIdentityContext,
) -> anyhow::Result<CreateIdentityResult> {
    let mut task = CreateIdentityTask::new(context);
    loop {
        match task.poll()? {
            CreateIdentityLoop::Instruction(instruction) => {
                let result = instruction.request.send(&http_client).await;
                task.response(CreateIdentityResponse { result })?;
            },

            CreateIdentityLoop::Done(result) => return Ok(result),
        }
    }
}

#[tokio::main]
async fn main() -> anyhow::Result<()> {
    // Parse arguments for command
    let arguments = CreateIdentityCommand::parse();

    // Configure logging
    let log_level = match arguments.verbose {
        1 => Level::DEBUG,
        2 => Level::TRACE,
        _ => Level::INFO,
    };
    init_stderr_logging(log_level);

    // Create HTTP client
    let http_client = https_client_builder().build()?;
    let config = CommonConfig::from_options(&http_client, arguments.config).await?;

    // Create identity
    let CreateIdentityResult {
        identity,
        client_key,
        server_group,
    } = run_create_identity(
        http_client,
        CreateIdentityContext {
            client_info: ClientInfo::Libthreema,
            config: config.config,
            flavor: config.flavor,
        },
    )
    .await?;
    println!("--threema-id {identity}");
    println!(
        "--client-key {}",
        HEXLOWER_PERMISSIVE.encode(client_key.as_bytes())
    );
    println!("--csp-server-group {}", server_group.as_str());
    Ok(())
}

#[test]
fn verify_cli() {
    use clap::CommandFactory;
    CreateIdentityCommand::command().debug_assert();
}

Messung
CHZG
859010091

¤ Dauer der Verarbeitung: 0.2 Sekunden  ¤

*© Formatika GbR, Deutschland






Wurzel

Suchen

PVS Prover

Isabelle Prover


Cephes Mathematical Library

Vienna Development Method

Haftungshinweis

Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.

Bemerkung:

Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.






                                                                                                                                                                                                                                                                                                                                                                                                     


Neuigkeiten

     Aktuelles
     Motto des Tages

Open Source Software

     Quellcodebibliothek
     Eigene Quellcodes
     Fremde Quellcodes
     Suchen

Jenseits des Üblichen ....
    

Besucherstatistik

Besucherstatistik

Statistik
#Sources=1104857
#Domains=439526