pub enum DlcKey {
Private {
privkey: PrivateKey,
pubkey: PublicKey,
},
Public {
pubkey: PublicKey,
},
}Expand description
Client-side wrapper for Ed25519 key operations: verify tokens and (when private) create compact signed tokens.
Variants§
Private
Private key (protected seed + public bytes + public key tag)
Fields
privkey: PrivateKeyProtected signing seed (secure wrapper)
Public
Public-only key (public bytes)
Implementations§
Source§impl DlcKey
impl DlcKey
pub fn new(pubkey: &str, privkey: &str) -> Result<Self, DlcError>
Sourcepub fn public(pubkey: &str) -> Result<Self, DlcError>
pub fn public(pubkey: &str) -> Result<Self, DlcError>
Construct a DlcKey::Public from a base64url-encoded public key string.
Sourcepub fn generate_random() -> Self
pub fn generate_random() -> Self
Generate a new DlcKey::Private with a random seed and derived public key.
The public key is derived from the generated seed so the keypair is valid.
pub fn get_public_key(&self) -> &PublicKey
Sourcepub fn sign(&self, data: &[u8]) -> Result<[u8; 64], DlcError>
pub fn sign(&self, data: &[u8]) -> Result<[u8; 64], DlcError>
Sign data using the private key. Returns a 64-byte signature.
Sourcepub fn verify(&self, data: &[u8], signature: &[u8; 64]) -> Result<(), DlcError>
pub fn verify(&self, data: &[u8], signature: &[u8; 64]) -> Result<(), DlcError>
Verify a 64-byte Ed25519 signature against provided data.
Sourcepub fn create_signed_license<D>(
&self,
dlcs: impl IntoIterator<Item = D>,
product: Product,
) -> Result<SignedLicense, DlcError>where
D: Display,
pub fn create_signed_license<D>(
&self,
dlcs: impl IntoIterator<Item = D>,
product: Product,
) -> Result<SignedLicense, DlcError>where
D: Display,
Create a compact offline-signed token that can be verified by this key’s public key.
Returns a SignedLicense (zeroized on drop). The license payload includes
the provided DLC ids and product binding.
Create a compact offline-signed token (SignedLicense).
Sourcepub fn extend_signed_license<D>(
&self,
existing: &SignedLicense,
new_dlcs: impl IntoIterator<Item = D>,
product: Product,
) -> Result<SignedLicense, DlcError>where
D: Display,
pub fn extend_signed_license<D>(
&self,
existing: &SignedLicense,
new_dlcs: impl IntoIterator<Item = D>,
product: Product,
) -> Result<SignedLicense, DlcError>where
D: Display,
Extend an existing signed license by merging additional DLC ids while preserving backwards compatibility.
Extracts the DLC ids from an existing (unsigned or unverified) license payload, merges them with the provided new DLC ids (with deduplication), and creates a fresh signed license with the combined list. The product must match this key’s current product.
Important: This creates a NEW signed token with a potentially different signature, but the payload contains all previous DLC ids plus the new ones. Existing DLC packs remain unlocked by the new license.
§Example
use bevy_dlc::{DlcKey, SignedLicense, Product};
// in a real program you would obtain a key and product from your build
// process or configuration. we use simple constructors here so the
// example compiles without panicking.
let dlc_key: DlcKey = DlcKey::generate_random();
let product: Product = Product::from("my_game");
let old_license = SignedLicense::from("...existing token...");
let _new_license = dlc_key
.extend_signed_license(&old_license, &["new_expansion"], product)
.unwrap();Sourcepub fn verify_signed_license(&self, license: &SignedLicense) -> bool
pub fn verify_signed_license(&self, license: &SignedLicense) -> bool
Verify a compact signed-license (signature + payload) using this key’s public key Verify a compact signed-license using this key’s public key.
Returns true if the signature is valid and the token is well-formed,
false otherwise. No further payload validation is performed.
Trait Implementations§
impl Resource for DlcKey
Auto Trait Implementations§
impl Freeze for DlcKey
impl RefUnwindSafe for DlcKey
impl Send for DlcKey
impl Sync for DlcKey
impl Unpin for DlcKey
impl UnsafeUnpin for DlcKey
impl UnwindSafe for DlcKey
Blanket Implementations§
Source§impl<T, U> AsBindGroupShaderType<U> for T
impl<T, U> AsBindGroupShaderType<U> for T
Source§fn as_bind_group_shader_type(&self, _images: &RenderAssets<GpuImage>) -> U
fn as_bind_group_shader_type(&self, _images: &RenderAssets<GpuImage>) -> U
T ShaderType for self. When used in AsBindGroup
derives, it is safe to assume that all images in self exist.Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be
downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further
downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSend for T
impl<T> DowncastSend for T
Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<S> FromSample<S> for S
impl<S> FromSample<S> for S
fn from_sample_(s: S) -> S
Source§impl<T, W> HasTypeWitness<W> for Twhere
W: MakeTypeWitness<Arg = T>,
T: ?Sized,
impl<T, W> HasTypeWitness<W> for Twhere
W: MakeTypeWitness<Arg = T>,
T: ?Sized,
Source§impl<T> Identity for Twhere
T: ?Sized,
impl<T> Identity for Twhere
T: ?Sized,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more