pub struct Credential {
pub protocol: Option<String>,
pub host: Option<String>,
pub path: Option<String>,
pub username: Option<String>,
pub password: Option<String>,
pub url: Option<String>,
pub extra: Vec<(String, String)>,
}Expand description
A structured Git credential.
Mirrors the fields Git’s credential protocol exchanges. Round-trips through
the key=value\n…\n\n wire format via Credential::parse and
Credential::serialize. Any keys outside the named fields below
(capability[], authtype, password_expiry_utc, …) are preserved in
extra so they survive a parse/serialize round-trip
and are forwarded to helpers unchanged.
Fields§
§protocol: Option<String>protocol field (e.g. https, http, ssh).
host: Option<String>host field, optionally including a :port suffix.
path: Option<String>path field (repository path on the host).
username: Option<String>username field.
password: Option<String>password field (the secret).
url: Option<String>url field — a full URL Git can decompose into the fields above.
extra: Vec<(String, String)>Any additional key=value pairs, in wire order. Multi-valued keys such
as capability[] may appear more than once.
Implementations§
Source§impl Credential
impl Credential
Sourcepub fn parse(input: &str) -> Self
pub fn parse(input: &str) -> Self
Parse a credential from Git’s key=value\n… wire format.
Parsing stops at the first blank line (Git’s record terminator) or at
EOF. Trailing \r is stripped from each line so the parser accepts both
LF and CRLF input. Lines without an = are ignored.
Sourcepub fn parse_bytes(bytes: &[u8]) -> Self
pub fn parse_bytes(bytes: &[u8]) -> Self
Parse from raw bytes (lossy UTF-8); convenience for helper stdout.
Sourcepub fn serialize(&self) -> String
pub fn serialize(&self) -> String
Serialize to Git’s key=value\n wire format (no trailing blank line).
Fields are emitted in Git’s canonical order
(protocol, host, path, username, password, url) followed by any
extra entries in their stored order.
Sourcepub fn is_complete(&self) -> bool
pub fn is_complete(&self) -> bool
True when the credential carries a usable username and password.
Sourcepub fn target_url(&self) -> Option<String>
pub fn target_url(&self) -> Option<String>
The URL this credential authenticates against, for matching
credential.<url>.helper config entries. Prefers an explicit
url; otherwise reconstructs it from
protocol/host/path (matching Git’s credential_apply_config).
Trait Implementations§
Source§impl Clone for Credential
impl Clone for Credential
Source§fn clone(&self) -> Credential
fn clone(&self) -> Credential
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for Credential
impl Debug for Credential
Source§impl Default for Credential
impl Default for Credential
Source§fn default() -> Credential
fn default() -> Credential
impl Eq for Credential
Source§impl PartialEq for Credential
impl PartialEq for Credential
Source§fn eq(&self, other: &Credential) -> bool
fn eq(&self, other: &Credential) -> bool
self and other values to be equal, and is used by ==.