aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--crates/shirabe/src/autoload/autoload_generator.rs30
-rw-r--r--crates/shirabe/src/autoload/class_map_generator.rs21
-rw-r--r--crates/shirabe/src/autoload/mod.rs2
-rw-r--r--crates/shirabe/src/command/base_command.rs23
-rw-r--r--crates/shirabe/src/installed_versions.rs35
-rw-r--r--crates/shirabe/src/installer.rs54
-rw-r--r--crates/shirabe/src/json/json_file.rs7
-rw-r--r--crates/shirabe/src/json/json_formatter.rs120
-rw-r--r--crates/shirabe/src/json/mod.rs2
-rw-r--r--crates/shirabe/src/plugin/post_file_download_event.rs2
-rw-r--r--crates/shirabe/src/repository/mod.rs2
-rw-r--r--crates/shirabe/src/repository/pear_repository.rs18
-rw-r--r--crates/shirabe/src/repository/platform_repository.rs2
-rw-r--r--crates/shirabe/src/self_update/versions.rs2
-rw-r--r--crates/shirabe/src/util/auth_helper.rs47
-rw-r--r--crates/shirabe/src/util/git.rs3
-rw-r--r--crates/shirabe/src/util/metadata_minifier.rs1
-rw-r--r--crates/shirabe/src/util/mod.rs4
-rw-r--r--crates/shirabe/src/util/tls_helper.rs193
19 files changed, 14 insertions, 554 deletions
diff --git a/crates/shirabe/src/autoload/autoload_generator.rs b/crates/shirabe/src/autoload/autoload_generator.rs
index 6505510..54f67a5 100644
--- a/crates/shirabe/src/autoload/autoload_generator.rs
+++ b/crates/shirabe/src/autoload/autoload_generator.rs
@@ -7,12 +7,12 @@ use shirabe_class_map_generator::class_map_generator::ClassMapGenerator;
use shirabe_external_packages::composer::pcre::{CaptureKey, Preg};
use shirabe_external_packages::symfony::component::console::formatter::OutputFormatter;
use shirabe_php_shim::{
- E_USER_DEPRECATED, InvalidArgumentException, PhpMixed, RuntimeException, array_filter,
- array_keys, array_map, array_merge, array_merge_map, array_merge_recursive, array_reverse,
- array_shift, array_slice, array_slice_strs, array_unique, bin2hex, explode, file_exists,
- file_get_contents, hash, implode, in_array, is_array, krsort, ksort, ltrim, preg_quote,
- random_bytes, realpath, sprintf, str_contains, str_replace, str_starts_with, strlen, strpos,
- strtr, substr, substr_count, trigger_error, trim, unlink, var_export,
+ InvalidArgumentException, PhpMixed, RuntimeException, array_filter, array_keys, array_map,
+ array_merge, array_merge_map, array_merge_recursive, array_reverse, array_shift, array_slice,
+ array_slice_strs, array_unique, bin2hex, explode, file_exists, file_get_contents, hash,
+ implode, in_array, is_array, krsort, ksort, ltrim, preg_quote, random_bytes, realpath, sprintf,
+ str_contains, str_replace, str_starts_with, strlen, strpos, strtr, substr, substr_count, trim,
+ unlink, var_export,
};
use shirabe_semver::constraint::AnyConstraint;
use shirabe_semver::constraint::Bound;
@@ -97,24 +97,6 @@ impl AutoloadGenerator {
self.dry_run = dry_run;
}
- /// Whether platform requirements should be ignored.
- ///
- /// If this is set to true, the platform check file will not be generated
- /// If this is set to false, the platform check file will be generated with all requirements
- /// If this is set to string[], those packages will be ignored from the platform check file
- ///
- /// Deprecated: use setPlatformRequirementFilter instead
- pub fn set_ignore_platform_requirements(&mut self, ignore_platform_reqs: PhpMixed) {
- trigger_error(
- "AutoloadGenerator::setIgnorePlatformRequirements is deprecated since Composer 2.2, use setPlatformRequirementFilter instead.",
- E_USER_DEPRECATED,
- );
-
- self.set_platform_requirement_filter(
- PlatformRequirementFilterFactory::from_bool_or_list(ignore_platform_reqs).unwrap(),
- );
- }
-
pub fn set_platform_requirement_filter(
&mut self,
platform_requirement_filter: std::rc::Rc<dyn PlatformRequirementFilterInterface>,
diff --git a/crates/shirabe/src/autoload/class_map_generator.rs b/crates/shirabe/src/autoload/class_map_generator.rs
deleted file mode 100644
index 06dc34d..0000000
--- a/crates/shirabe/src/autoload/class_map_generator.rs
+++ /dev/null
@@ -1,21 +0,0 @@
-//! ref: composer/src/Composer/Autoload/ClassMapGenerator.php
-
-/// `Composer\Autoload\ClassMapGenerator`.
-///
-/// Deprecated since Composer 2.4.0 in favor of the composer/class-map-generator
-/// package (`shirabe-class-map-generator`), which Composer itself now uses
-/// directly. Composer's own code no longer references this class, so its
-/// `dump` / `createMap` methods are intentionally left unported.
-///
-/// Even though it is deprecated, plugins may still use it, so this type will
-/// eventually have to be implemented alongside plugin API support. It is left
-/// here intentionally so that implementation is not forgotten.
-///
-/// TODO(plugin): implement `dump` / `createMap` for plugins still relying on
-/// this deprecated class.
-#[derive(Debug)]
-#[deprecated(
- since = "Composer 2.4.0",
- note = "use the composer/class-map-generator package (shirabe-class-map-generator) instead"
-)]
-pub struct ClassMapGenerator;
diff --git a/crates/shirabe/src/autoload/mod.rs b/crates/shirabe/src/autoload/mod.rs
index cb0be1c..d5758b2 100644
--- a/crates/shirabe/src/autoload/mod.rs
+++ b/crates/shirabe/src/autoload/mod.rs
@@ -1,7 +1,5 @@
pub mod autoload_generator;
pub mod class_loader;
-pub mod class_map_generator;
pub use autoload_generator::*;
pub use class_loader::*;
-pub use class_map_generator::*;
diff --git a/crates/shirabe/src/command/base_command.rs b/crates/shirabe/src/command/base_command.rs
index b6664e7..8aff0d9 100644
--- a/crates/shirabe/src/command/base_command.rs
+++ b/crates/shirabe/src/command/base_command.rs
@@ -157,14 +157,6 @@ pub trait BaseCommand {
/// Gets the application instance for this command.
fn get_application(&self) -> Result<Application>;
- /// @deprecated since Composer 2.3.0 use requireComposer or tryComposer depending on whether you have $required set to true or false
- fn get_composer(
- &mut self,
- required: bool,
- disable_plugins: Option<bool>,
- disable_scripts: Option<bool>,
- ) -> Result<Option<PartialComposerHandle>>;
-
/// Retrieves the default Composer\Composer instance or throws
fn require_composer(
&mut self,
@@ -295,21 +287,6 @@ impl<C: HasBaseCommandData> BaseCommand for C {
todo!()
}
- fn get_composer(
- &mut self,
- required: bool,
- disable_plugins: Option<bool>,
- disable_scripts: Option<bool>,
- ) -> Result<Option<PartialComposerHandle>> {
- if required {
- return Ok(Some(
- self.require_composer(disable_plugins, disable_scripts)?,
- ));
- }
-
- Ok(self.try_composer(disable_plugins, disable_scripts))
- }
-
fn require_composer(
&mut self,
_disable_plugins: Option<bool>,
diff --git a/crates/shirabe/src/installed_versions.rs b/crates/shirabe/src/installed_versions.rs
index d52deac..90f0c60 100644
--- a/crates/shirabe/src/installed_versions.rs
+++ b/crates/shirabe/src/installed_versions.rs
@@ -5,9 +5,8 @@ use std::sync::Mutex;
use anyhow::Result;
use indexmap::IndexMap;
use shirabe_php_shim::{
- E_USER_DEPRECATED, OutOfBoundsException, PhpMixed, array_flip, array_keys, array_merge,
- call_user_func_array, implode, is_file, method_exists, php_dir, require_php_file, strtr_array,
- substr, trigger_error,
+ OutOfBoundsException, PhpMixed, array_flip, array_keys, array_merge, call_user_func_array,
+ implode, is_file, method_exists, php_dir, require_php_file, strtr_array, substr,
};
use shirabe_semver::version_parser::VersionParser;
@@ -393,36 +392,6 @@ impl InstalledVersions {
.unwrap_or_default()
}
- /// Returns the raw installed.php data for custom implementations
- ///
- /// @deprecated Use getAllRawData() instead which returns all datasets for all autoloaders present in the process. getRawData only returns the first dataset loaded, which may not be what you expect.
- /// @return array[]
- pub fn get_raw_data() -> IndexMap<String, PhpMixed> {
- // PHP: @trigger_error(...)
- // TODO(phase-b): Silencer::call wraps trigger_error
- trigger_error(
- "getRawData only returns the first dataset loaded, which may not be what you expect. Use getAllRawData() instead which returns all datasets for all autoloaders present in the process.",
- E_USER_DEPRECATED,
- );
-
- let mut installed = INSTALLED.lock().unwrap();
- if installed.is_none() {
- // only require the installed.php file if this file is loaded from its dumped location,
- // and not from its source location in the composer/composer package, see https://github.com/composer/composer/issues/9937
- if substr(&php_dir(), -8, Some(1)) != "C" {
- let required = require_php_file(&format!("{}/installed.php", php_dir()));
- *installed = required
- .as_array()
- .cloned()
- .map(|m| m.into_iter().map(|(k, v)| (k, *v)).collect());
- } else {
- *installed = Some(IndexMap::new());
- }
- }
-
- installed.clone().unwrap_or_default()
- }
-
/// Returns the raw data of all installed.php which are currently loaded for custom implementations
///
/// @return array[]
diff --git a/crates/shirabe/src/installer.rs b/crates/shirabe/src/installer.rs
index 2783364..ff8a80d 100644
--- a/crates/shirabe/src/installer.rs
+++ b/crates/shirabe/src/installer.rs
@@ -38,7 +38,7 @@ use shirabe_php_shim::{
PhpMixed, RuntimeException, array_flip, array_map, array_merge, array_unique, array_values,
clone, count, defined, gc_collect_cycles, gc_disable, gc_enable, get_class, implode, in_array,
intval, is_dir, is_numeric, is_string, max_i64, sprintf, strcmp, strpos, strtolower, touch,
- trigger_error, usort,
+ usort,
};
use shirabe_semver;
@@ -1828,17 +1828,6 @@ impl Installer {
self
}
- /// set whether to run scripts or not
- ///
- /// This is disabled implicitly when enabling dryRun
- ///
- /// Deprecated: Use setRunScripts(false) on the EventDispatcher instance being injected instead
- pub fn set_run_scripts(&mut self, run_scripts: bool) -> &mut Self {
- self.run_scripts = run_scripts;
-
- self
- }
-
/// set the config instance
pub fn set_config(&mut self, config: std::rc::Rc<std::cell::RefCell<Config>>) -> &mut Self {
self.config = config;
@@ -1858,27 +1847,6 @@ impl Installer {
self.verbose
}
- /// set ignore Platform Package requirements
- ///
- /// If this is set to true, all platform requirements are ignored
- /// If this is set to false, no platform requirements are ignored
- /// If this is set to string[], those packages will be ignored
- ///
- /// Deprecated: use setPlatformRequirementFilter instead
- pub fn set_ignore_platform_requirements(
- &mut self,
- ignore_platform_reqs: shirabe_php_shim::PhpMixed,
- ) -> anyhow::Result<&mut Self> {
- trigger_error(
- "Installer::setIgnorePlatformRequirements is deprecated since Composer 2.2, use setPlatformRequirementFilter instead.",
- shirabe_php_shim::E_USER_DEPRECATED,
- );
-
- Ok(self.set_platform_requirement_filter(
- PlatformRequirementFilterFactory::from_bool_or_list(ignore_platform_reqs)?,
- ))
- }
-
pub fn set_platform_requirement_filter(
&mut self,
platform_requirement_filter: std::rc::Rc<dyn PlatformRequirementFilterInterface>,
@@ -1976,16 +1944,6 @@ impl Installer {
self
}
- /// Should an audit be run after installation is complete?
- ///
- /// Deprecated: Use setAuditConfig instead of calling this
- pub fn set_audit(&mut self, audit: bool) -> &mut Self {
- self.audit = audit;
- self.audit_config = None; // Invalidate cached config
-
- self
- }
-
/// Should exit with status code 5 on audit error
pub fn set_error_on_audit(&mut self, error_on_audit: bool) -> &mut Self {
self.error_on_audit = error_on_audit;
@@ -1993,16 +1951,6 @@ impl Installer {
self
}
- /// What format should be used for audit output?
- ///
- /// Deprecated: Use setAuditConfig instead of calling this
- pub fn set_audit_format(&mut self, audit_format: String) -> &mut Self {
- self.audit_format = audit_format;
- self.audit_config = None; // Invalidate cached config
-
- self
- }
-
/// Sets a custom AuditConfig to override the default configuration from Config
pub fn set_audit_config(&mut self, audit_config: AuditConfig) -> &mut Self {
self.audit_config = Some(audit_config);
diff --git a/crates/shirabe/src/json/json_file.rs b/crates/shirabe/src/json/json_file.rs
index 0aa44fc..b8372b9 100644
--- a/crates/shirabe/src/json/json_file.rs
+++ b/crates/shirabe/src/json/json_file.rs
@@ -87,13 +87,6 @@ impl JsonFile {
pub const AUTH_SCHEMA: i64 = 3;
pub const LOCK_SCHEMA: i64 = 4;
- /// @deprecated Use \JSON_UNESCAPED_SLASHES
- pub const JSON_UNESCAPED_SLASHES: i64 = 64;
- /// @deprecated Use \JSON_PRETTY_PRINT
- pub const JSON_PRETTY_PRINT: i64 = 128;
- /// @deprecated Use \JSON_UNESCAPED_UNICODE
- pub const JSON_UNESCAPED_UNICODE: i64 = 256;
-
pub const INDENT_DEFAULT: &'static str = " ";
/// PHP: __DIR__ . '/../../../res/composer-schema.json'
diff --git a/crates/shirabe/src/json/json_formatter.rs b/crates/shirabe/src/json/json_formatter.rs
deleted file mode 100644
index 260bf1e..0000000
--- a/crates/shirabe/src/json/json_formatter.rs
+++ /dev/null
@@ -1,120 +0,0 @@
-//! ref: composer/src/Composer/Json/JsonFormatter.php
-
-use shirabe_external_packages::composer::pcre::{CaptureKey, Preg};
-use shirabe_php_shim::{PhpMixed, function_exists, mb_convert_encoding, pack};
-
-pub struct JsonFormatter;
-
-impl JsonFormatter {
- /**
- * This code is based on the function found at:
- * http://recursive-design.com/blog/2008/03/11/format-json-with-php/
- *
- * Originally licensed under MIT by Dave Perrett <mail@recursive-design.com>
- */
- pub fn format(json: String, unescape_unicode: bool, unescape_slashes: bool) -> String {
- let mut result = String::new();
- let mut pos: usize = 0;
- let indent_str = " ";
- let new_line = "\n";
- let mut out_of_quotes = true;
- let mut buffer = String::new();
- let mut noescape = true;
-
- let chars: Vec<char> = json.chars().collect();
- let str_len = chars.len();
-
- for i in 0..str_len {
- let char_ = chars[i];
-
- if char_ == '"' && noescape {
- out_of_quotes = !out_of_quotes;
- }
-
- if !out_of_quotes {
- buffer.push(char_);
- noescape = if char_ == '\\' { !noescape } else { true };
- continue;
- }
- if !buffer.is_empty() {
- if unescape_slashes {
- buffer = buffer.replace("\\/", "/");
- }
-
- if unescape_unicode && function_exists("mb_convert_encoding") {
- buffer = Preg::replace_callback(
- r"/(\\+)u([0-9a-f]{4})/i",
- |matches: &indexmap::IndexMap<CaptureKey, String>| -> String {
- let m0 = matches
- .get(&CaptureKey::ByIndex(0))
- .cloned()
- .unwrap_or_default();
- let m1 = matches
- .get(&CaptureKey::ByIndex(1))
- .cloned()
- .unwrap_or_default();
- let m2 = matches
- .get(&CaptureKey::ByIndex(2))
- .cloned()
- .unwrap_or_default();
- let l = m1.len();
-
- if l % 2 != 0 {
- let code = i64::from_str_radix(&m2, 16).unwrap_or(0);
- if code >= 0xD800 && code <= 0xDFFF {
- return m0;
- }
-
- return "\\".repeat(l - 1)
- + &mb_convert_encoding(
- pack("H*", &[PhpMixed::String(m2)]),
- "UTF-8",
- "UCS-2BE",
- );
- }
-
- m0
- },
- &buffer,
- )
- .unwrap_or(buffer);
- }
-
- result.push_str(&buffer);
- result.push(char_);
- buffer = String::new();
- continue;
- }
-
- let mut char_str = char_.to_string();
-
- if char_ == ':' {
- char_str.push(' ');
- } else if char_ == '}' || char_ == ']' {
- pos -= 1;
- let prev_char = if i > 0 { chars[i - 1] } else { '\0' };
-
- if prev_char != '{' && prev_char != '[' {
- result.push_str(new_line);
- result.push_str(&indent_str.repeat(pos));
- } else {
- result = result.trim_end().to_string();
- }
- }
-
- result.push_str(&char_str);
-
- if char_ == ',' || char_ == '{' || char_ == '[' {
- result.push_str(new_line);
-
- if char_ == '{' || char_ == '[' {
- pos += 1;
- }
-
- result.push_str(&indent_str.repeat(pos));
- }
- }
-
- result
- }
-}
diff --git a/crates/shirabe/src/json/mod.rs b/crates/shirabe/src/json/mod.rs
index 0863529..36b5b6d 100644
--- a/crates/shirabe/src/json/mod.rs
+++ b/crates/shirabe/src/json/mod.rs
@@ -1,9 +1,7 @@
pub mod json_file;
-pub mod json_formatter;
pub mod json_manipulator;
pub mod json_validation_exception;
pub use json_file::*;
-pub use json_formatter::*;
pub use json_manipulator::*;
pub use json_validation_exception::*;
diff --git a/crates/shirabe/src/plugin/post_file_download_event.rs b/crates/shirabe/src/plugin/post_file_download_event.rs
index 46d52c0..2124f1e 100644
--- a/crates/shirabe/src/plugin/post_file_download_event.rs
+++ b/crates/shirabe/src/plugin/post_file_download_event.rs
@@ -53,8 +53,6 @@ impl PostFileDownloadEvent {
&self.context
}
- // TODO(plugin): getPackage is deprecated since Composer 2.1, use getContext instead
-
pub fn get_type(&self) -> &str {
&self.r#type
}
diff --git a/crates/shirabe/src/repository/mod.rs b/crates/shirabe/src/repository/mod.rs
index d678764..478eedd 100644
--- a/crates/shirabe/src/repository/mod.rs
+++ b/crates/shirabe/src/repository/mod.rs
@@ -16,7 +16,6 @@ pub mod invalid_repository_exception;
pub mod lock_array_repository;
pub mod package_repository;
pub mod path_repository;
-pub mod pear_repository;
pub mod platform_repository;
pub mod repository_factory;
pub mod repository_interface;
@@ -49,7 +48,6 @@ pub use invalid_repository_exception::*;
pub use lock_array_repository::*;
pub use package_repository::*;
pub use path_repository::*;
-pub use pear_repository::*;
pub use platform_repository::*;
pub use repository_factory::*;
pub use repository_interface::*;
diff --git a/crates/shirabe/src/repository/pear_repository.rs b/crates/shirabe/src/repository/pear_repository.rs
deleted file mode 100644
index 1f0e29e..0000000
--- a/crates/shirabe/src/repository/pear_repository.rs
+++ /dev/null
@@ -1,18 +0,0 @@
-//! ref: composer/src/Composer/Repository/PearRepository.php
-
-use super::ArrayRepository;
-use shirabe_php_shim::InvalidArgumentException;
-
-#[derive(Debug)]
-pub struct PearRepository {
- inner: ArrayRepository,
-}
-
-impl PearRepository {
- pub fn new() -> anyhow::Result<Self> {
- Err(anyhow::anyhow!(InvalidArgumentException {
- message: "The PEAR repository has been removed from Composer 2.x".to_string(),
- code: 0,
- }))
- }
-}
diff --git a/crates/shirabe/src/repository/platform_repository.rs b/crates/shirabe/src/repository/platform_repository.rs
index 3a59475..f194e69 100644
--- a/crates/shirabe/src/repository/platform_repository.rs
+++ b/crates/shirabe/src/repository/platform_repository.rs
@@ -55,7 +55,7 @@ pub struct PlatformRepository {
}
impl PlatformRepository {
- pub const PLATFORM_PACKAGE_REGEX: &'static str = "{^(?:php(?:-64bit|-ipv6|-zts|-debug)?|hhvm|(?:ext|lib)-[a-z0-9](?:[_.-]?[a-z0-9]+)*|composer(?:-(?:plugin|runtime)-api)?)$}iD";
+ const PLATFORM_PACKAGE_REGEX: &'static str = "{^(?:php(?:-64bit|-ipv6|-zts|-debug)?|hhvm|(?:ext|lib)-[a-z0-9](?:[_.-]?[a-z0-9]+)*|composer(?:-(?:plugin|runtime)-api)?)$}iD";
pub fn new(
packages: Vec<PackageInterfaceHandle>,
diff --git a/crates/shirabe/src/self_update/versions.rs b/crates/shirabe/src/self_update/versions.rs
index 88b0a45..c8c3f54 100644
--- a/crates/shirabe/src/self_update/versions.rs
+++ b/crates/shirabe/src/self_update/versions.rs
@@ -12,7 +12,6 @@ use shirabe_php_shim::{
};
pub struct Versions {
- pub channels: Vec<String>,
http_downloader: std::rc::Rc<std::cell::RefCell<HttpDownloader>>,
config: std::rc::Rc<std::cell::RefCell<Config>>,
channel: Option<String>,
@@ -36,7 +35,6 @@ impl Versions {
http_downloader: std::rc::Rc<std::cell::RefCell<HttpDownloader>>,
) -> Self {
Self {
- channels: Self::CHANNELS.iter().map(|s| s.to_string()).collect(),
http_downloader,
config,
channel: None,
diff --git a/crates/shirabe/src/util/auth_helper.rs b/crates/shirabe/src/util/auth_helper.rs
index 0465b10..61970f2 100644
--- a/crates/shirabe/src/util/auth_helper.rs
+++ b/crates/shirabe/src/util/auth_helper.rs
@@ -5,9 +5,9 @@ use anyhow::Result;
use indexmap::IndexMap;
use shirabe_external_packages::composer::pcre::Preg;
use shirabe_php_shim::{
- E_USER_DEPRECATED, PHP_URL_HOST, PHP_URL_PATH, PHP_URL_SCHEME, PhpMixed, RuntimeException,
- base64_encode, explode, in_array, is_array, is_string, json_decode, parse_url, sprintf,
- str_replace, strpos, strtolower, substr, trigger_error, trim,
+ PHP_URL_HOST, PHP_URL_PATH, PHP_URL_SCHEME, PhpMixed, RuntimeException, base64_encode, explode,
+ in_array, is_array, is_string, json_decode, parse_url, sprintf, str_replace, strpos,
+ strtolower, substr, trim,
};
use crate::config::Config;
@@ -478,47 +478,6 @@ impl AuthHelper {
})
}
- /// @deprecated use addAuthenticationOptions instead
- ///
- /// @param string[] $headers
- ///
- /// @return string[] updated headers array
- pub fn add_authentication_header(
- &mut self,
- headers: Vec<String>,
- origin: &str,
- url: &str,
- ) -> Result<Vec<String>> {
- trigger_error(
- "AuthHelper::addAuthenticationHeader is deprecated since Composer 2.9 use addAuthenticationOptions instead.",
- E_USER_DEPRECATED,
- );
-
- // PHP: $options = ['http' => ['header' => &$headers]];
- // PHP uses references so subsequent mutations affect $headers
- let mut options: IndexMap<String, PhpMixed> = IndexMap::new();
- let mut http: IndexMap<String, Box<PhpMixed>> = IndexMap::new();
- http.insert(
- "header".to_string(),
- Box::new(PhpMixed::List(
- headers
- .iter()
- .map(|h| Box::new(PhpMixed::String(h.clone())))
- .collect(),
- )),
- );
- options.insert("http".to_string(), PhpMixed::Array(http));
-
- let options = self.add_authentication_options(options, origin, url)?;
-
- let http = options.get("http").and_then(|v| v.as_array()).unwrap();
- let header = http.get("header").and_then(|v| v.as_list()).unwrap();
- Ok(header
- .iter()
- .filter_map(|v| v.as_string().map(|s| s.to_string()))
- .collect())
- }
-
/// @param array<string, mixed> $options
///
/// @return array<string, mixed> updated options
diff --git a/crates/shirabe/src/util/git.rs b/crates/shirabe/src/util/git.rs
index b2438c7..7e9619c 100644
--- a/crates/shirabe/src/util/git.rs
+++ b/crates/shirabe/src/util/git.rs
@@ -135,8 +135,7 @@ impl Git {
/// @param callable|array<callable> $commandCallable
/// @param mixed $commandOutput the output will be written into this var if passed by ref
/// if a callable is passed it will be used as output handler
- /// @deprecated Use runCommands with placeholders instead of callbacks for simplicity
- pub fn run_command(
+ fn run_command(
&mut self,
command_callable: Vec<Box<dyn Fn(&str) -> Vec<String>>>,
url: &str,
diff --git a/crates/shirabe/src/util/metadata_minifier.rs b/crates/shirabe/src/util/metadata_minifier.rs
deleted file mode 100644
index ddad547..0000000
--- a/crates/shirabe/src/util/metadata_minifier.rs
+++ /dev/null
@@ -1 +0,0 @@
-//! ref: composer/src/Composer/Util/MetadataMinifier.php
diff --git a/crates/shirabe/src/util/mod.rs b/crates/shirabe/src/util/mod.rs
index 633928b..d34fce5 100644
--- a/crates/shirabe/src/util/mod.rs
+++ b/crates/shirabe/src/util/mod.rs
@@ -15,7 +15,6 @@ pub mod http;
pub mod http_downloader;
pub mod ini_helper;
pub mod r#loop;
-pub mod metadata_minifier;
pub mod no_proxy_pattern;
pub mod package_info;
pub mod package_sorter;
@@ -28,7 +27,6 @@ pub mod stream_context_factory;
pub mod svn;
pub mod sync_helper;
pub mod tar;
-pub mod tls_helper;
pub mod url;
pub mod zip;
@@ -48,7 +46,6 @@ pub use hg::*;
pub use http::*;
pub use http_downloader::*;
pub use ini_helper::*;
-pub use metadata_minifier::*;
pub use no_proxy_pattern::*;
pub use package_info::*;
pub use package_sorter::*;
@@ -61,6 +58,5 @@ pub use stream_context_factory::*;
pub use svn::*;
pub use sync_helper::*;
pub use tar::*;
-pub use tls_helper::*;
pub use url::*;
pub use zip::*;
diff --git a/crates/shirabe/src/util/tls_helper.rs b/crates/shirabe/src/util/tls_helper.rs
deleted file mode 100644
index 0c20dd4..0000000
--- a/crates/shirabe/src/util/tls_helper.rs
+++ /dev/null
@@ -1,193 +0,0 @@
-//! ref: composer/src/Composer/Util/TlsHelper.php
-
-use shirabe_external_packages::composer::ca_bundle::CaBundle;
-use shirabe_external_packages::composer::pcre::Preg;
-use shirabe_php_shim::{
- PhpMixed, RuntimeException, base64_decode, openssl_get_publickey, openssl_pkey_get_details,
- openssl_x509_parse, preg_quote, substr_count,
-};
-
-/// @deprecated Use composer/ca-bundle and composer/composer 2.2 if you still need PHP 5 compatibility
-pub struct TlsHelper;
-
-impl TlsHelper {
- pub fn check_certificate_host(
- certificate: &PhpMixed,
- hostname: &str,
- cn: &mut Option<String>,
- ) -> bool {
- let names = match Self::get_certificate_names(certificate) {
- Some(n) => n,
- None => return false,
- };
-
- let mut combined_names = names.san.clone();
- combined_names.push(names.cn.clone());
- let hostname = hostname.to_lowercase();
-
- for cert_name in &combined_names {
- if let Some(matcher) = Self::cert_name_matcher(cert_name) {
- if matcher(&hostname) {
- *cn = Some(names.cn.clone());
- return true;
- }
- }
- }
-
- false
- }
-
- pub fn get_certificate_names(certificate: &PhpMixed) -> Option<CertificateNames> {
- let info = match certificate {
- PhpMixed::Array(arr) => arr.clone(),
- _ => {
- if CaBundle::is_openssl_parse_safe() {
- if let PhpMixed::String(cert_str) = certificate {
- openssl_x509_parse(cert_str, false)?
- } else {
- return None;
- }
- } else {
- return None;
- }
- }
- };
-
- let common_name = info
- .get("subject")
- .and_then(|v| v.as_array())
- .and_then(|subj| subj.get("commonName"))
- .and_then(|cn| cn.as_string())
- .map(|s| s.to_lowercase())?;
-
- let mut subject_alt_names = vec![];
- if let Some(san_value) = info
- .get("extensions")
- .and_then(|v| v.as_array())
- .and_then(|ext| ext.get("subjectAltName"))
- .and_then(|v| v.as_string())
- {
- let parts = Preg::split(r"{\s*,\s*}", san_value).unwrap_or_default();
- for name in parts {
- if name.starts_with("DNS:") {
- let dns = name[4..].trim_start().to_lowercase();
- subject_alt_names.push(dns);
- }
- }
- }
-
- Some(CertificateNames {
- cn: common_name,
- san: subject_alt_names,
- })
- }
-
- /// Get the certificate pin.
- ///
- /// By Kevin McArthur of StormTide Digital Studios Inc.
- /// @KevinSMcArthur / https://github.com/StormTide
- ///
- /// See https://tools.ietf.org/html/draft-ietf-websec-key-pinning-02
- ///
- /// This method was adapted from Sslurp.
- /// https://github.com/EvanDotPro/Sslurp
- ///
- /// (c) Evan Coury <me@evancoury.com>
- ///
- /// For the full copyright and license information, please see below:
- ///
- /// Copyright (c) 2013, Evan Coury
- /// All rights reserved.
- ///
- /// Redistribution and use in source and binary forms, with or without modification,
- /// are permitted provided that the following conditions are met:
- ///
- /// * Redistributions of source code must retain the above copyright notice,
- /// this list of conditions and the following disclaimer.
- ///
- /// * Redistributions in binary form must reproduce the above copyright notice,
- /// this list of conditions and the following disclaimer in the documentation
- /// and/or other materials provided with the distribution.
- ///
- /// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- /// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- /// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- /// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- /// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- /// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- /// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- /// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- /// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- /// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- pub fn get_certificate_fingerprint(certificate: &str) -> anyhow::Result<String> {
- let pubkey = openssl_get_publickey(certificate).ok_or_else(|| RuntimeException {
- message: "Failed to retrieve the public key from certificate".to_string(),
- code: 0,
- })?;
- let pubkeydetails = openssl_pkey_get_details(pubkey).ok_or_else(|| RuntimeException {
- message: "Failed to retrieve public key details".to_string(),
- code: 0,
- })?;
- let pubkeypem = pubkeydetails
- .get("key")
- .and_then(|v| v.as_string())
- .unwrap_or("")
- .to_string();
-
- let start = "-----BEGIN PUBLIC KEY-----";
- let end = "-----END PUBLIC KEY-----";
- let start_pos = pubkeypem.find(start).unwrap_or(0) + start.len();
- let end_pos = pubkeypem.rfind(end).unwrap_or(pubkeypem.len());
- let pemtrim = &pubkeypem[start_pos..end_pos];
-
- let der = base64_decode(pemtrim).unwrap_or_default();
-
- Ok(shirabe_php_shim::hash(
- "sha1",
- &String::from_utf8_lossy(&der),
- ))
- }
-
- pub fn is_openssl_parse_safe() -> bool {
- CaBundle::is_openssl_parse_safe()
- }
-
- fn cert_name_matcher(cert_name: &str) -> Option<Box<dyn Fn(&str) -> bool>> {
- let wildcards = substr_count(cert_name, "*");
-
- if wildcards == 0 {
- let name = cert_name.to_string();
- return Some(Box::new(move |hostname: &str| hostname == name));
- }
-
- if wildcards == 1 {
- let components: Vec<&str> = cert_name.split('.').collect();
-
- if components.len() < 3 {
- return None;
- }
-
- let first_component = components[0];
-
- if !first_component.ends_with('*') {
- return None;
- }
-
- let mut wildcard_regex = preg_quote(cert_name, None);
- wildcard_regex = wildcard_regex.replace("\\*", "[a-z0-9-]+");
- let wildcard_regex = format!("{{^{}$}}", wildcard_regex);
-
- return Some(Box::new(move |hostname: &str| {
- Preg::is_match(&wildcard_regex, hostname).unwrap_or(false)
- }));
- }
-
- None
- }
-}
-
-#[derive(Debug)]
-pub struct CertificateNames {
- pub cn: String,
- pub san: Vec<String>,
-}