@@ -83,42 +83,74 @@ def __str__(self) -> str:
8383class TrustedRoot (_TrustedRoot ):
8484 """Complete set of trusted entities for a Sigstore client"""
8585
86- def __init__ ( self , args : Optional [Namespace ] = None ):
87- self . args = args
86+ args : Optional [Namespace ] = None
87+ purpose : KeyringPurpose
8888
8989 @classmethod
90- def from_file (cls , path : str ) -> "TrustedRoot" :
90+ def from_file (
91+ cls ,
92+ path : str ,
93+ args : Optional [Namespace ] = None ,
94+ purpose : KeyringPurpose = KeyringPurpose .VERIFY ,
95+ ) -> "TrustedRoot" :
9196 """Create a new trust root from file"""
92- tr : TrustedRoot = cls ().from_json (Path (path ).read_bytes ())
93- return tr
97+ trusted_root : TrustedRoot = cls ().from_json (Path (path ).read_bytes ())
98+ trusted_root .args = args
99+ trusted_root .purpose = purpose
100+ return trusted_root
94101
95102 @classmethod
96- def from_tuf (cls , url : str , offline : bool = False ) -> "TrustedRoot" :
103+ def from_tuf (
104+ cls ,
105+ url : str ,
106+ offline : bool = False ,
107+ args : Optional [Namespace ] = None ,
108+ purpose : KeyringPurpose = KeyringPurpose .VERIFY ,
109+ ) -> "TrustedRoot" :
97110 """Create a new trust root from a TUF repository.
98111
99112 If `offline`, will use trust root in local TUF cache. Otherwise will
100113 update the trust root from remote TUF repository.
101114 """
102115 path = TrustUpdater (url , offline ).get_trusted_root_path ()
103- return cls .from_file (path )
116+ trusted_root = cls .from_file (path )
117+ trusted_root .args = args
118+ trusted_root .purpose = purpose
119+ return trusted_root
104120
105121 @classmethod
106- def production (cls , offline : bool = False ) -> "TrustedRoot" :
122+ def production (
123+ cls ,
124+ offline : bool = False ,
125+ args : Optional [Namespace ] = None ,
126+ purpose : KeyringPurpose = KeyringPurpose .VERIFY ,
127+ ) -> "TrustedRoot" :
107128 """Create new trust root from Sigstore production TUF repository.
108129
109130 If `offline`, will use trust root in local TUF cache. Otherwise will
110131 update the trust root from remote TUF repository.
111132 """
112- return cls .from_tuf (DEFAULT_TUF_URL , offline )
133+ trusted_root = cls .from_tuf (DEFAULT_TUF_URL , offline )
134+ trusted_root .args = args
135+ trusted_root .purpose = purpose
136+ return trusted_root
113137
114138 @classmethod
115- def staging (cls , offline : bool = False ) -> "TrustedRoot" :
139+ def staging (
140+ cls ,
141+ offline : bool = False ,
142+ args : Optional [Namespace ] = None ,
143+ purpose : KeyringPurpose = KeyringPurpose .VERIFY ,
144+ ) -> "TrustedRoot" :
116145 """Create new trust root from Sigstore staging TUF repository.
117146
118147 If `offline`, will use trust root in local TUF cache. Otherwise will
119148 update the trust root from remote TUF repository.
120149 """
121- return cls .from_tuf (STAGING_TUF_URL , offline )
150+ trusted_root = cls .from_tuf (STAGING_TUF_URL , offline )
151+ trusted_root .args = args
152+ trusted_root .purpose = purpose
153+ return trusted_root
122154
123155 @staticmethod
124156 def _get_tlog_keys (
@@ -147,13 +179,10 @@ def _get_ca_keys(
147179 for cert in ca .cert_chain .certificates :
148180 yield cert .raw_bytes
149181
150- def set_args (self , args : Namespace ) -> None :
151- self .args = args
152-
153- def rekor_keyring (self , purpose : KeyringPurpose ) -> RekorKeyring :
182+ def rekor_keyring (self ) -> RekorKeyring :
154183 """Return public key contents given certificate authorities."""
155184
156- return RekorKeyring (self ._get_rekor_keys (purpose ))
185+ return RekorKeyring (self ._get_rekor_keys ())
157186
158187 def get_ctfe_keys (self ) -> list [bytes ]:
159188 """Return the CTFE public keys contents."""
@@ -164,13 +193,13 @@ def get_ctfe_keys(self) -> list[bytes]:
164193 raise MetadataError ("CTFE keys not found in trusted root" )
165194 return ctfes
166195
167- def _get_rekor_keys (self , purpose : KeyringPurpose ) -> Keyring :
196+ def _get_rekor_keys (self ) -> Keyring :
168197 """Return the rekor public key content."""
169198 keys : list [bytes ]
170199 if self .args and self .args .rekor_root_pubkey :
171200 keys = self .args .rekor_root_pubkey .read ()
172201 else :
173- keys = list (self ._get_tlog_keys (self .tlogs , purpose ))
202+ keys = list (self ._get_tlog_keys (self .tlogs , self . purpose ))
174203 if len (keys ) != 1 :
175204 raise MetadataError ("Did not find one Rekor key in trusted root" )
176205 return Keyring (keys )
0 commit comments