Skip to content

Commit

Permalink
Unify core and custom profiles under one type
Browse files Browse the repository at this point in the history
  • Loading branch information
rschulman committed Jan 13, 2025
1 parent 17b3702 commit 09fc119
Show file tree
Hide file tree
Showing 35 changed files with 210 additions and 78 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ anyhow = "1.0.86"
sha2 = "0.10.8"
form_urlencoded = "1.2.1"
percent-encoding = "2.3.1"
serde_cbor = "0.11.2"

[dev-dependencies]
assert-json-diff = "2.0.2"
Expand Down
15 changes: 8 additions & 7 deletions src/authorization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,11 @@ mod test {
use serde_json::json;

use crate::{
core::{
metadata::AuthorizationServerMetadata,
profiles::core::{
metadata::CredentialIssuerMetadata,
profiles::{jwt_vc_json, CoreProfilesAuthorizationDetailsObject},
},
metadata::AuthorizationServerMetadata,
types::CredentialUrl,
};

Expand Down Expand Up @@ -193,7 +193,7 @@ mod test {

#[test]
fn example_authorization_details_multiple() {
let _: Vec<crate::core::authorization::AuthorizationDetailsObject> =
let _: Vec<crate::profiles::core::authorization::AuthorizationDetailsObject> =
serde_json::from_value(json!([
{
"type":"openid_credential",
Expand Down Expand Up @@ -238,7 +238,7 @@ mod test {
AuthUrl::new("https://server.example.com/authorize".into()).unwrap(),
));

let client = crate::core::client::Client::from_issuer_metadata(
let client = crate::profiles::core::client::Client::from_issuer_metadata(
ClientId::new("s6BhdRkqt3".to_string()),
RedirectUrl::new("https://client.example.org/cb".into()).unwrap(),
credential_issuer_metadata,
Expand All @@ -259,9 +259,10 @@ mod test {
let authorization_details = vec![AuthorizationDetailsObject {
r#type: AuthorizationDetailsObjectType::OpenidCredential,
additional_profile_fields: CoreProfilesAuthorizationDetailsObject::WithFormat {
inner: crate::core::profiles::AuthorizationDetailsObjectWithFormat::JwtVcJson(
authorization_detail,
),
inner:
crate::profiles::core::profiles::AuthorizationDetailsObjectWithFormat::JwtVcJson(
authorization_detail,
),
_credential_identifier: (),
},
locations: vec![],
Expand Down
10 changes: 0 additions & 10 deletions src/core/profiles/mso_mdoc/credential_response.rs

This file was deleted.

10 changes: 5 additions & 5 deletions src/credential.rs
Original file line number Diff line number Diff line change
Expand Up @@ -453,13 +453,13 @@ pub struct DeferredRequest {
mod test {
use serde_json::json;

use crate::core::profiles::CoreProfilesCredentialResponse;
use crate::profiles::core::profiles::CoreProfilesCredentialResponse;

use super::*;

#[test]
fn example_credential_request_object() {
let _: crate::core::credential::Request = serde_json::from_value(json!({
let _: crate::profiles::core::credential::Request = serde_json::from_value(json!({
"format": "jwt_vc_json",
"credential_definition": {
"type": [
Expand All @@ -480,7 +480,7 @@ mod test {

#[test]
fn example_credential_request_referenced() {
let _: crate::core::credential::Request = serde_json::from_value(json!({
let _: crate::profiles::core::credential::Request = serde_json::from_value(json!({
"credential_identifier": "UniversityDegreeCredential",
"proof": {
"proof_type": "jwt",
Expand All @@ -496,7 +496,7 @@ mod test {
#[test]
fn example_credential_request_deny() {
assert!(
serde_json::from_value::<crate::core::credential::Request>(json!({
serde_json::from_value::<crate::profiles::core::credential::Request>(json!({
"format": "jwt_vc_json",
"credential_identifier": "UniversityDegreeCredential",
"proof": {
Expand Down Expand Up @@ -545,7 +545,7 @@ mod test {

#[test]
fn example_batch_request() {
let _: crate::core::credential::BatchRequest = serde_json::from_value(json!({
let _: crate::profiles::core::credential::BatchRequest = serde_json::from_value(json!({
"credential_requests":[
{
"format":"jwt_vc_json",
Expand Down
12 changes: 5 additions & 7 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@ mod macros;

pub mod authorization;
pub mod client;
pub mod core;
pub mod credential;
pub mod credential_offer;
pub mod credential_response_encryption;
pub mod custom;
mod deny_field;
mod http_utils;
pub mod metadata;
Expand All @@ -23,15 +21,15 @@ pub use oauth2;

#[cfg(test)]
mod test {
use crate::core::profiles::{
jwt_vc_json_ld, ldp_vc, CoreProfilesCredentialConfiguration, CoreProfilesCredentialRequest,
CredentialRequestWithFormat,
};
use crate::core::{client::Client, metadata::CredentialIssuerMetadata};
use crate::credential_offer::CredentialOffer;
use crate::metadata::authorization_server::GrantType;
use crate::metadata::credential_issuer::CredentialConfiguration;
use crate::metadata::{AuthorizationServerMetadata, MetadataDiscovery};
use crate::profiles::core::profiles::{
jwt_vc_json_ld, ldp_vc, CoreProfilesCredentialConfiguration, CoreProfilesCredentialRequest,
CredentialRequestWithFormat,
};
use crate::profiles::core::{client::Client, metadata::CredentialIssuerMetadata};
use crate::types::CredentialOfferRequest;
use oauth2::{ClientId, RedirectUrl, TokenResponse};
use url::Url;
Expand Down
2 changes: 1 addition & 1 deletion src/metadata/credential_issuer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ impl MetadataBackgroundImage {

#[cfg(test)]
mod test {
use crate::core::profiles::CoreProfilesCredentialConfiguration;
use crate::profiles::core::profiles::CoreProfilesCredentialConfiguration;
use serde_json::json;

use super::*;
Expand Down
18 changes: 0 additions & 18 deletions src/profiles.rs

This file was deleted.

File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ use std::collections::HashMap;
use serde::{Deserialize, Serialize};

use crate::{
core::profiles::AuthorizationDetailsObjectClaim, profiles::AuthorizationDetailsObjectProfile,
profiles::core::profiles::AuthorizationDetailsObjectClaim,
profiles::AuthorizationDetailsObjectProfile,
};

use super::{CredentialSubjectClaims, Format};
Expand Down Expand Up @@ -83,7 +84,7 @@ mod test {

use crate::{
authorization::AuthorizationDetailsObject,
core::profiles::CoreProfilesAuthorizationDetailsObject,
profiles::core::profiles::CoreProfilesAuthorizationDetailsObject,
};

#[test]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ use std::collections::HashMap;
use serde::{Deserialize, Serialize};

use crate::{
core::profiles::CredentialConfigurationClaim, profiles::CredentialConfigurationProfile,
profiles::core::profiles::CredentialConfigurationClaim,
profiles::CredentialConfigurationProfile,
};

use super::{CredentialSubjectClaims, Format};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ impl CredentialRequestProfile for CredentialRequest {
mod test {
use serde_json::json;

use crate::{core::profiles::CoreProfilesCredentialRequest, credential::Request};
use crate::{credential::Request, profiles::core::profiles::CoreProfilesCredentialRequest};

#[test]
fn roundtrip_with_format() {
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ use serde::{de::DeserializeOwned, Deserialize, Serialize};
use serde_json::Value;

use crate::{
core::profiles::AuthorizationDetailsObjectClaim, profiles::AuthorizationDetailsObjectProfile,
profiles::core::profiles::AuthorizationDetailsObjectClaim,
profiles::AuthorizationDetailsObjectProfile,
};

use super::CredentialSubjectClaims;
Expand Down Expand Up @@ -91,7 +92,7 @@ mod test {

use crate::{
authorization::AuthorizationDetailsObject,
core::profiles::{ldp_vc::Format, CoreProfilesAuthorizationDetailsObject},
profiles::core::profiles::{ldp_vc::Format, CoreProfilesAuthorizationDetailsObject},
};

#[test]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ use serde::{de::DeserializeOwned, Deserialize, Serialize};
use serde_json::Value;

use crate::{
core::profiles::CredentialConfigurationClaim, profiles::CredentialConfigurationProfile,
profiles::core::profiles::CredentialConfigurationClaim,
profiles::CredentialConfigurationProfile,
};

use super::CredentialSubjectClaims;
Expand Down Expand Up @@ -65,7 +66,8 @@ mod test {
use serde_json::json;

use crate::{
core::profiles::ldp_vc::Format, metadata::credential_issuer::CredentialConfiguration,
metadata::credential_issuer::CredentialConfiguration,
profiles::core::profiles::ldp_vc::Format,
};

#[test]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ mod test {
use serde_json::json;

use crate::{
core::profiles::{ldp_vc::Format, CoreProfilesCredentialRequest},
credential::Request,
profiles::core::profiles::{ldp_vc::Format, CoreProfilesCredentialRequest},
};

#[test]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
use serde::{Deserialize, Serialize};
use serde_json::Value;
use ssi::prelude::{AnySuite, DataIntegrity, DataIntegrityDocument};

use crate::profiles::CredentialResponseProfile;

#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct CredentialResponse;

impl CredentialResponseProfile for CredentialResponse {
type Type = Value;
type Type = DataIntegrity<DataIntegrityDocument, AnySuite>;
}

#[cfg(test)]
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ use isomdl::definitions::device_request::DocType;
use serde::{Deserialize, Serialize};

use crate::{
core::profiles::AuthorizationDetailsObjectClaim, profiles::AuthorizationDetailsObjectProfile,
profiles::core::profiles::AuthorizationDetailsObjectClaim,
profiles::AuthorizationDetailsObjectProfile,
};

use super::{Claims, Format};
Expand Down Expand Up @@ -60,7 +61,7 @@ mod test {

use crate::{
authorization::AuthorizationDetailsObject,
core::profiles::CoreProfilesAuthorizationDetailsObject,
profiles::core::profiles::CoreProfilesAuthorizationDetailsObject,
};

#[test]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ use isomdl::definitions::device_request::DocType;
use serde::{Deserialize, Serialize};

use crate::{
core::profiles::CredentialConfigurationClaim, profiles::CredentialConfigurationProfile,
profiles::core::profiles::CredentialConfigurationClaim,
profiles::CredentialConfigurationProfile,
};

use super::{Claims, Format};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use isomdl::definitions::device_request::DocType;
use serde::{Deserialize, Serialize};

use crate::{core::profiles::CredentialConfigurationClaim, profiles::CredentialRequestProfile};
use crate::{
profiles::core::profiles::CredentialConfigurationClaim, profiles::CredentialRequestProfile,
};

use super::{Claims, Format};

Expand Down Expand Up @@ -70,7 +72,7 @@ impl CredentialRequestProfile for CredentialRequest {
mod test {
use serde_json::json;

use crate::{core::profiles::CoreProfilesCredentialRequest, credential::Request};
use crate::{credential::Request, profiles::core::profiles::CoreProfilesCredentialRequest};

#[test]
fn roundtrip_with_format() {
Expand Down
41 changes: 41 additions & 0 deletions src/profiles/core/profiles/mso_mdoc/credential_response.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
use isomdl::definitions::IssuerSigned;
use serde::{Deserialize, Serialize};

use crate::profiles::CredentialResponseProfile;

#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct CredentialResponse;

impl CredentialResponseProfile for CredentialResponse {
type Type = IsoIssuerSigned;
}

#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct IsoIssuerSigned(#[serde(with = "base64_cbor")] IssuerSigned);

mod base64_cbor {
use base64::{engine::general_purpose::URL_SAFE, Engine};
use serde::{de::DeserializeOwned, Deserialize, Deserializer, Serialize, Serializer};

pub fn serialize<T: Sized + Serialize, S: Serializer>(v: &T, s: S) -> Result<S::Ok, S::Error> {
let v = match serde_cbor::to_vec(v) {
Ok(v) => v,
Err(e) => return Err(serde::ser::Error::custom(e)),
};
let b64 = URL_SAFE.encode(v);
String::serialize(&b64, s)
}

pub fn deserialize<'de, T: DeserializeOwned, D: Deserializer<'de>>(
d: D,
) -> Result<T, D::Error> {
let b64 = String::deserialize(d)?;
match URL_SAFE.decode(b64) {
Ok(v) => match serde_cbor::from_slice(&v) {
Ok(v) => Ok(v),
Err(e) => Err(serde::de::Error::custom(e)),
},
Err(e) => Err(serde::de::Error::custom(e)),
}
}
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use serde::{Deserialize, Serialize};

use crate::{
core::profiles::CredentialConfigurationClaim, profiles::AuthorizationDetailsObjectProfile,
use crate::profiles::custom::profiles::{
AuthorizationDetailsObjectProfile, CredentialConfigurationClaim,
};

use super::{Claims, Format};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use serde::{Deserialize, Serialize};

use crate::{
core::profiles::CredentialConfigurationClaim, profiles::CredentialConfigurationProfile,
profiles::custom::profiles::CredentialConfigurationClaim,
profiles::CredentialConfigurationProfile,
};

use super::{Claims, Format};
Expand Down
Loading

0 comments on commit 09fc119

Please sign in to comment.