21 个版本 (稳定版)

2.0.5 2024 年 8 月 20 日
2.0.0 2024 年 7 月 23 日
1.1.0 2024 年 7 月 25 日
0.1.13 2024 年 4 月 3 日
0.1.0 2023 年 9 月 16 日

#386密码学

Download history 157/week @ 2024-04-29 181/week @ 2024-05-06 386/week @ 2024-05-13 356/week @ 2024-05-20 222/week @ 2024-05-27 91/week @ 2024-06-03 84/week @ 2024-06-10 251/week @ 2024-06-17 94/week @ 2024-06-24 89/week @ 2024-07-01 378/week @ 2024-07-08 311/week @ 2024-07-15 383/week @ 2024-07-22 152/week @ 2024-07-29 575/week @ 2024-08-05 585/week @ 2024-08-12

1,698 每月下载量

Apache-2.0

715KB
15K SLoC

Antimatter Rust 库

Antimatter 是一个 数据控制平面。它允许您无论数据存储在哪里或哪些客户端正在访问它,都可以控制您的数据。

请参阅开发者文档以获取更多信息


lib.rs:

Antimatter

此crate提供了一些用于与Antimatter服务及其内部托管的域交互的函数。有关更多信息,请访问https://docs.antimatter.io

模块

此crate分为2个模块,如下所述。

会话

这主要关注建立与Antimatter服务的连接,并对其进行API请求以控制您的数据。这些包括但不限于

  • 身份验证和连接管理。
  • 数据封装和相关API调用。
  • 打开封装数据和相关API调用。
  • 数据分类。
  • 数据访问策略执行。

胶囊

这里主要关注与加密、解密、存储和检索数据相关的操作。此模块在主机设备上执行的操作。此模块包含

  • AEAD (带有关联数据的认证加密) 逻辑。
  • 胶囊格式。
  • 胶囊捆绑逻辑。
  • 从不同的来源和目的地读取和写入胶囊的逻辑。

用法

您需要有效的Antimatter域及其API密钥才能继续。首先,在您的环境中设置有效Antimatter域的API密钥

export ANTIMATTER_API_KEY=<domain's API key>

然后,您需要将此crate包含在您的 Cargo.toml

[dependencies]
antimatter = "0.1.13"

最后,以下是将一些数据封装到文件中然后打开它的基本示例

use antimatter::{capsule::common::Column, capsule::common::CellReader, session::session::{EncapsulateConfig, Session}};
use std::collections::HashMap;

fn main() {
    // Create a Session object. This will use the provided domain ID
    // here and API key set in this environment.
    let domain = "<your domain ID here>".to_string();
    let api_key = "<your API key>".to_string();
    let mut session = Session::new(domain, api_key).unwrap();

    // We generate configuration for encapsulating data with. At a minimum
    // we need to provide a valid write-context in the domain. We also
    // provide some extra information, but this is not required.
    let encapsulate_cfg = EncapsulateConfig {
        write_context_name: "data-writer".to_string(),
        extra: "Some extra information".to_string(),
        subdomain: None,
        subdomain_from: None,
        create_subdomains: None,
        async_seal: false,
    };

    // Provide a file path to write and read from.
    let path = "/tmp/basic_capsule.amr.ca".to_string();

    // We are going to encapsulate a table of data. In order to this we
    // first need to define the columns in the table. We do this by
    // providing a Vector of Column. In this example, we only give the
    // columns names.
    let column_defn = vec![
        Column {
            name: "col1".to_string(),
            tags: vec![],
            skip_classification: false,
        },
        Column {
            name: "col2".to_string(),
            tags: vec![],
            skip_classification: false,
        },
    ];

    // We then define the table of data. This is a 2D Vector of bytes. We
    // lay out the table in a 2x2 grid and fill each element with bytes.
    //
    //  (r1, c1) | (r1, c2)
    //  ---------+---------
    //  (r2, c1) | (r2, c2)
    //
    let data_table = vec![
        vec![
            CellReader::new(
                vec![],
                std::io::Cursor::new(
                    "(r1, c1)".as_bytes().to_vec()),
                ).expect("failed to create CellReader"),
            CellReader::new(
                vec![],
                std::io::Cursor::new(
                    "(r1, c2)".as_bytes().to_vec()),
                ).expect("failed to create CellReader")
        ],
        vec![
            CellReader::new(
                vec![],
                std::io::Cursor::new(
                    "(r2, c1)".as_bytes().to_vec()),
                ).expect("failed to create CellReader"),
            CellReader::new(
                vec![],
                std::io::Cursor::new(
                    "(r2, c2)".as_bytes().to_vec()),
                ).expect("failed to create CellReader")
        ]
    ];

    // Then encapsulate to file. This will handle all the necessary API
    // calls to Antimatter's services to encapsulate the table provided,
    // and if your write-context used includes classification hooks, these
    // will also be invoked and data in the provided table enriched with
    // tagging information.
    session.encapsulate_to_local_file(
        column_defn,
        data_table,
        vec![],
        encapsulate_cfg,
        path.clone(),
    )
    .expect("failed to encapsulate");

    // We then immediately open the file and read it with the provided
    // read-context. Any policies attached to the read-context will be
    // enforced, and data redacted, as part of the reading process.
    let mut file = Box::new(std::fs::File::open(path).expect("failed to open file"));
    let mut capsule = session.open(
        "data-reader",
        HashMap::new(),
        HashMap::new(),
        Box::leak(file),
    )
    .unwrap();

    let (_span_tags, data) = capsule
        .read_all(&vec![])
        .expect("failed to read from capsule");

    // Finally we print out the read data.
    for row in data {
        for col in row {
            print!("{} ", String::from_utf8(col).unwrap());
        }
        println!("");
    }
}

依赖关系

~44–60MB
~1M SLoC