• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

polyphony-chat / sonata / 16389521442

19 Jul 2025 02:13PM UTC coverage: 86.719% (-4.8%) from 91.484%
16389521442

push

github

bitfl0wer
feat: impl get_idcert_by for HomeServerCert
chore: remove unneeded import

17 of 52 branches covered (32.69%)

Branch coverage included in aggregate %.

0 of 33 new or added lines in 1 file covered. (0.0%)

649 of 716 relevant lines covered (90.64%)

3613.06 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/database/idcert.rs
1
use chrono::NaiveDateTime;
2
use log::error;
3
use polyproto::{
4
        certs::{PublicKeyInfo, idcert::IdCert},
5
        key::PublicKey,
6
        signature::Signature,
7
        types::DomainName,
8
};
9
use sqlx::query;
10

11
use crate::{database::Database, errors::Error};
12

13
pub(crate) struct HomeServerCert;
14

15
impl HomeServerCert {
16
        /// TODO documentme
NEW
17
        pub(crate) async fn get_idcert_by<S: Signature, P: PublicKey<S>>(
×
NEW
18
                db: &Database,
×
NEW
19
                issuer_domain_name: &DomainName,
×
NEW
20
                timestamp: &NaiveDateTime,
×
NEW
21
        ) -> Result<Option<IdCert<S, P>>, Error> {
×
NEW
22
                let issuer_components =
×
NEW
23
                        issuer_domain_name.to_string().split('.').map(|s| s.to_owned()).collect::<Vec<_>>();
×
NEW
24
                let Some(idcert_table_record) = query!(
×
25
                        r#"
26
        WITH issuer AS (
27
            SELECT id
28
            FROM issuers
29
            WHERE domain_components = $1
30
        )
31
        SELECT idcert.pem_encoded, idcert.home_server_public_key_id
32
        FROM idcert
33
        JOIN issuer i ON idcert.issuer_info_id = i.id
34
        WHERE (
35
            $2 >= valid_not_before AND $2 <= valid_not_after
36
        )
37
    "#,
38
                        issuer_components.as_slice(),
39
                        timestamp
40
                )
NEW
41
                .fetch_optional(&db.pool)
×
NEW
42
                .await?
×
43
                else {
NEW
44
                        return Ok(None);
×
45
                };
46

NEW
47
                let pem_encoded_pubkey_info = query!(
×
48
                        r#"
49
        SELECT pubkey
50
        FROM public_keys
51
        WHERE id = $1
52
    "#,
53
                        idcert_table_record.home_server_public_key_id
54
                )
NEW
55
                .fetch_one(&db.pool)
×
NEW
56
                .await?;
×
NEW
57
                IdCert::from_pem(
×
NEW
58
                        &idcert_table_record.pem_encoded,
×
NEW
59
                        polyproto::certs::Target::HomeServer,
×
NEW
60
                        timestamp.and_utc().timestamp() as u64,
×
NEW
61
                        &P::try_from_public_key_info(
×
NEW
62
                                PublicKeyInfo::from_pem(&pem_encoded_pubkey_info.pubkey).map_err(|e| {
×
NEW
63
                                        error!("Error parsing public key info: {e}");
×
NEW
64
                                        Error::new_internal_error(None)
×
NEW
65
                                })?,
×
66
                        )
NEW
67
                        .map_err(|e| {
×
NEW
68
                                error!("Error creating public key from public key info: {e}");
×
NEW
69
                                Error::new_internal_error(None)
×
NEW
70
                        })?,
×
71
                )
NEW
72
                .map_err(|e| {
×
NEW
73
                        error!("Error parsing home server certificate: {e}");
×
NEW
74
                        Error::new_internal_error(None)
×
NEW
75
                })
×
NEW
76
                .map(Some)
×
NEW
77
        }
×
78
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc