Resolve the signing identity for this change. Mirrors `resolve_author`'s precedence: `--identity` flag, then `--usage` default, then the global default identity. Loads the identity's keypair from the store. Returns `None` when no identity is available (the change records unsigned, with a warning).
(
&self,
)
| 120 | /// identity's keypair from the store. Returns `None` when no identity is |
| 121 | /// available (the change records unsigned, with a warning). |
| 122 | pub(super) fn resolve_signing_identity( |
| 123 | &self, |
| 124 | ) -> CliResult<Option<atomic_repository::record::SigningIdentity>> { |
| 125 | use atomic_canonical::did::did_for_public_key; |
| 126 | |
| 127 | let store = match IdentityStore::open_default() { |
| 128 | Ok(store) => store, |
| 129 | Err(_) => return Ok(None), |
| 130 | }; |
| 131 | |
| 132 | // 1. --identity flag |
| 133 | let identity = if let Some(identity_name) = &self.identity { |
| 134 | store |
| 135 | .load_by_name(identity_name) |
| 136 | .map_err(|_| CliError::IdentityNotFound(identity_name.clone()))? |
| 137 | // 2. --usage default |
| 138 | } else if let Some(usage_str) = &self.usage { |
| 139 | let usage = IdentityUsage::parse(usage_str); |
| 140 | match store.get_default_for_usage(&usage) { |
| 141 | Ok(Some(identity)) => identity, |
| 142 | _ => return Ok(None), |
| 143 | } |
| 144 | // 3. Global default |
| 145 | } else { |
| 146 | match store.get_default() { |
| 147 | Ok(Some(identity)) => identity, |
| 148 | _ => return Ok(None), |
| 149 | } |
| 150 | }; |
| 151 | |
| 152 | // Load the private key. A verification-only identity (no secret key |
| 153 | // on disk) cannot sign — record unsigned rather than fail. |
| 154 | let keypair = match store.load_keypair(&identity.id, None) { |
| 155 | Ok(keypair) => keypair, |
| 156 | Err(_) => return Ok(None), |
| 157 | }; |
| 158 | |
| 159 | Ok(Some(atomic_repository::record::SigningIdentity { |
| 160 | signer_did: did_for_public_key(&identity.public_key), |
| 161 | secret_key: *keypair.secret.as_bytes(), |
| 162 | })) |
| 163 | } |
| 164 | |
| 165 | /// Get the commit message, potentially from editor. |
| 166 | /// |
no test coverage detected