Skip to content

Commit 8381198

Browse files
committed
feat: store signatures
1 parent 7d97d36 commit 8381198

File tree

158 files changed

+852518
-318
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

158 files changed

+852518
-318
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ semver = "1"
119119
serde = "1.0.183"
120120
serde-cyclonedx = "0.9.1"
121121
serde_json = "1.0.114"
122-
serde_with = "3.11.0"
122+
serde_with = { version = "3.12.0", features = ["base64"] }
123123
serde_yml = { package = "serde_yaml_ng", version = "0.10" }
124124
sha2 = "0.10.8"
125125
spdx = "0.10.6"

entity/src/advisory.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ pub struct Model {
2929
pub withdrawn: Option<OffsetDateTime>,
3030
pub title: Option<String>,
3131
pub labels: Labels,
32-
pub source_document_id: Option<Uuid>,
32+
pub source_document_id: Uuid,
3333
}
3434

3535
#[ComplexObject]

entity/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ pub mod sbom_package;
2929
pub mod sbom_package_cpe_ref;
3030
pub mod sbom_package_license;
3131
pub mod sbom_package_purl_ref;
32+
pub mod signature_type;
3233
pub mod source_document;
34+
pub mod source_document_signature;
3335
pub mod status;
3436
pub mod user_preferences;
3537
pub mod version_range;

entity/src/sbom.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ pub struct Model {
1919
pub suppliers: Vec<String>,
2020
pub data_licenses: Vec<String>,
2121

22-
pub source_document_id: Option<Uuid>,
22+
pub source_document_id: Uuid,
2323

2424
#[graphql(derived(owned, into = "HashMap<String,String>", with = "Labels::from"))]
2525
pub labels: Labels,

entity/src/signature_type.rs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
use sea_orm::{DeriveActiveEnum, EnumIter};
2+
use std::fmt;
3+
4+
#[derive(
5+
Debug,
6+
Copy,
7+
Clone,
8+
Hash,
9+
PartialEq,
10+
Eq,
11+
EnumIter,
12+
DeriveActiveEnum,
13+
strum::VariantArray,
14+
strum::EnumString,
15+
serde::Serialize,
16+
serde::Deserialize,
17+
utoipa::ToSchema,
18+
)]
19+
#[sea_orm(rs_type = "String", db_type = "Enum", enum_name = "signature_type")]
20+
#[serde(rename_all = "lowercase")]
21+
#[strum(serialize_all = "lowercase")]
22+
// When adding a new variant, also add this to the "signature_type" enum.
23+
pub enum SignatureType {
24+
#[sea_orm(string_value = "pgp")]
25+
Pgp,
26+
}
27+
28+
impl fmt::Display for SignatureType {
29+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
30+
write!(f, "{:?}", self)
31+
}
32+
}
33+
34+
#[cfg(test)]
35+
mod test {
36+
use super::*;
37+
38+
#[test]
39+
fn names() {
40+
assert_eq!(SignatureType::Pgp.to_string(), "pgp");
41+
}
42+
}

entity/src/source_document.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ pub struct Model {
1313
}
1414

1515
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
16-
pub enum Relation {}
16+
pub enum Relation {
17+
#[sea_orm(has_many = "super::source_document_signature::Entity")]
18+
Signature,
19+
}
1720

1821
impl ActiveModelBehavior for ActiveModel {}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
use crate::signature_type::SignatureType;
2+
use sea_orm::entity::prelude::*;
3+
4+
#[derive(Clone, Debug, PartialEq, Eq, DeriveEntityModel)]
5+
#[sea_orm(table_name = "source_document_signature")]
6+
pub struct Model {
7+
#[sea_orm(primary_key)]
8+
pub id: Uuid,
9+
pub document_id: Uuid,
10+
pub r#type: SignatureType,
11+
pub payload: Vec<u8>,
12+
}
13+
14+
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
15+
pub enum Relation {
16+
#[sea_orm(
17+
belongs_to = "super::source_document::Entity",
18+
from = "Column::DocumentId",
19+
to = "super::source_document::Column::Id"
20+
)]
21+
SourceDocument,
22+
}
23+
24+
impl ActiveModelBehavior for ActiveModel {}
25+
26+
impl Related<super::source_document::Entity> for Entity {
27+
fn to() -> RelationDef {
28+
Relation::SourceDocument.def()
29+
}
30+
}

etc/datasets/Makefile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,8 @@ ds3.zip:
1515
ds3-sboms.zip:
1616
-rm ds3-sbom.zip
1717
cd ds3 && zip -r ../ds3-sboms.zip ./spdx
18+
19+
.PHONY: ds6.zip
20+
ds6.zip:
21+
-rm ds6.zip
22+
cd ds6 && zip -r ../ds6.zip .

0 commit comments

Comments
 (0)