Parse password argument (str, bytes-like, or callable) Returns (immediate_password, callable) where: - immediate_password: Some(string) if password is str/bytes, None if callable - callable: Some(PyObjectRef) if password is callable, None otherwise
(
password: &OptionalArg<PyObjectRef>,
vm: &VirtualMachine,
)
| 2006 | /// - immediate_password: Some(string) if password is str/bytes, None if callable |
| 2007 | /// - callable: Some(PyObjectRef) if password is callable, None otherwise |
| 2008 | fn parse_password_argument( |
| 2009 | password: &OptionalArg<PyObjectRef>, |
| 2010 | vm: &VirtualMachine, |
| 2011 | ) -> PyResult<(Option<String>, Option<PyObjectRef>)> { |
| 2012 | match password { |
| 2013 | OptionalArg::Present(p) => { |
| 2014 | if vm.is_none(p) { |
| 2015 | return Ok((None, None)); |
| 2016 | } |
| 2017 | |
| 2018 | // Try string |
| 2019 | if let Ok(pwd_str) = PyUtf8StrRef::try_from_object(vm, p.clone()) { |
| 2020 | Ok((Some(pwd_str.as_str().to_owned()), None)) |
| 2021 | } |
| 2022 | // Try bytes-like |
| 2023 | else if let Ok(pwd_bytes_like) = ArgBytesLike::try_from_object(vm, p.clone()) |
| 2024 | { |
| 2025 | let pwd = String::from_utf8(pwd_bytes_like.borrow_buf().to_vec()) |
| 2026 | .map_err(|_| vm.new_type_error("password bytes must be valid UTF-8"))?; |
| 2027 | Ok((Some(pwd), None)) |
| 2028 | } |
| 2029 | // Try callable |
| 2030 | else if p.is_callable() { |
| 2031 | Ok((None, Some(p.clone()))) |
| 2032 | } else { |
| 2033 | Err(vm.new_type_error("password should be a string or callable")) |
| 2034 | } |
| 2035 | } |
| 2036 | _ => Ok((None, None)), |
| 2037 | } |
| 2038 | } |
| 2039 | |
| 2040 | /// Helper: Load certificates from file into existing store |
| 2041 | fn load_certs_from_file_helper( |
nothing calls this directly
no test coverage detected