| Crates.io | cedrus-cedar |
| lib.rs | cedrus-cedar |
| version | 0.1.0 |
| created_at | 2025-11-01 15:00:35.27401+00 |
| updated_at | 2025-11-01 15:00:35.27401+00 |
| description | Core library for Cedar Policy serialization and type bindings. |
| homepage | https://github.com/stratusmedia/cedrus |
| repository | https://github.com/stratusmedia/cedrus |
| max_upload_size | |
| id | 1912072 |
| size | 141,055 |
Core library for Cedar Policy serialization and type bindings.
cedrus-cedar provides Rust types and serialization/deserialization for Cedar Policy language constructs. It bridges between:
cedar-policy crate typesutoipa for API documentationEntityUid: Unique identifier for entities (type + id)Entity: Complete entity with attributes, parents, and tagsEntityAttr: Entity attribute values (strings, numbers, booleans, sets, records, entity references)Schema: Complete Cedar schema definitionTypeJson: Type definitions for entity attributesEntityType: Entity type definitions with shapes and member relationshipsAction: Action definitions with principal/resource constraintsPolicy: Static Cedar policy with effect, principal, action, resource, and conditionsTemplate: Policy template with slots for principals/resourcesTemplateLink: Instantiation of a template with specific valuesPolicySet: Collection of policies, templates, and template linksJsonExpr: Cedar expressions in JSON formatCondition: Policy conditions (when/unless clauses)PrincipalOp, ActionOp, ResourceOp: Policy scope operatorsuse cedrus_cedar::{Entity, EntityUid, entity::EntityAttr};
use std::collections::{HashMap, HashSet};
// Create an entity UID
let uid = EntityUid::new("MyApp::User".to_string(), "alice".to_string());
// Create entity attributes
let mut attrs = HashMap::new();
attrs.insert("email".to_string(), EntityAttr::String("alice@example.com".to_string()));
attrs.insert("age".to_string(), EntityAttr::Number(30));
// Create entity
let entity = Entity::new(uid, attrs, HashSet::new());
// Convert to Cedar policy entity
let cedar_entity = entity.to_cedar_entity(None)?;
use cedrus_cedar::Schema;
// Deserialize from JSON
let schema_json = r#"{"MyApp": {"entityTypes": {...}, "actions": {...}}}"#;
let schema: Schema = serde_json::from_str(schema_json)?;
// Convert to Cedar schema
let cedar_schema: cedar_policy::Schema = schema.try_into()?;
use cedrus_cedar::{Policy, PolicySet};
use std::collections::HashMap;
// Deserialize policy from JSON
let policy_json = r#"{"effect": "permit", "principal": {...}, ...}"#;
let policy: Policy = serde_json::from_str(policy_json)?;
// Create policy set
let mut policies = HashMap::new();
policies.insert("my-policy".to_string().into(), policy);
let policy_set = PolicySet {
static_policies: policies,
templates: HashMap::new(),
template_links: Vec::new(),
};
// Convert to Cedar policy set
let cedar_policy_set: cedar_policy::PolicySet = policy_set.try_into()?;
use cedrus_cedar::{Entity, proto};
use prost::Message;
// Convert to protobuf
let entity: Entity = /* ... */;
let proto_entity: proto::Entity = entity.into();
let bytes = proto_entity.encode_to_vec();
// Convert from protobuf
let decoded = proto::Entity::decode(&bytes[..])?;
let entity: Entity = decoded.into();
The library provides conversions between three representations:
JSON (serde) ←→ Rust Types ←→ Protobuf (prost)
↕
Cedar Policy Types
From<cedar_policy::T> / Into<cedar_policy::T>: Convert to/from Cedar typesFrom<proto::T> / Into<proto::T>: Convert to/from Protobuf typesSerialize / Deserialize: JSON serialization via serdeThe library uses a build script to generate Protobuf types from src/cedar.proto:
cargo build
Generated code is placed in $OUT_DIR/cedar.rs and included via include! macro.
cedar-policy: Official Cedar policy engineprost: Protobuf serializationserde: JSON serializationutoipa: OpenAPI schema generationThis library is used by:
It provides the foundational types for storing, transmitting, and processing Cedar policies across the Cedrus system.