/** * Add a key to the collection * * @param \SAML2\Certificate\Fingerprint $fingerprint */ public function add($fingerprint) { if (!$fingerprint instanceof Fingerprint) { throw InvalidArgumentException::invalidType('SAML2\\Certificate\\Fingerprint ', $fingerprint); } parent::add($fingerprint); }
/** * @param $message */ public function addError($message) { if (!is_string($message)) { throw InvalidArgumentException::invalidType('string', $message); } $this->errors[] = $message; }
/** * @param string $fingerPrint */ public function __construct($fingerPrint) { if (!is_string($fingerPrint)) { throw InvalidArgumentException::invalidType('string', $fingerPrint); } $this->contents = $fingerPrint; }
/** * @param string $destination */ public function __construct($destination) { if (!is_string($destination)) { throw InvalidArgumentException::invalidType('string', $destination); } $this->destination = $destination; }
/** * Add a key to the collection * * @param \SAML2\Certificate\Key $key */ public function add($key) { if (!$key instanceof Key) { throw InvalidArgumentException::invalidType('SAML2\\Certificate\\Key', $key); } parent::add($key); }
/** * @param string $file full absolute path to the file * * @return string */ public static function getFileContents($file) { if (!is_string($file)) { throw InvalidArgumentException::invalidType('string', $file); } if (!is_readable($file)) { throw new RuntimeException(sprintf('File "%s" does not exist or is not readable', $file)); } $contents = file_get_contents($file); if ($contents === false) { throw new RuntimeException(sprintf('Could not read from existing and readable file "%s"', $file)); } return $contents; }
public static function create($keyContents, $passphrase = null) { if (!is_string($keyContents)) { throw InvalidArgumentException::invalidType('string', $keyContents); } if ($passphrase && !is_string($passphrase)) { throw InvalidArgumentException::invalidType('string', $passphrase); } $keyData = array('PEM' => $keyContents, self::USAGE_ENCRYPTION => true); if ($passphrase) { $keyData['passphrase'] = $passphrase; } return new self($keyData); }
/** * Loads the fingerprints from a configurationValue * * @param \SAML2\Configuration\CertificateProvider $configuration * * @return \SAML2\Certificate\FingerprintCollection * * @deprecated */ public function loadFingerprints(CertificateProvider $configuration) { $fingerprints = $configuration->getCertificateFingerprints(); if (!is_array($fingerprints) && !$fingerprints instanceof \Traversable) { throw InvalidArgumentException::invalidType('array or instanceof \\Traversable', $fingerprints); } $collection = new FingerprintCollection(); foreach ($fingerprints as $fingerprint) { if (!is_string($fingerprint) && !(is_object($fingerprint) && method_exists($fingerprint, '__toString'))) { throw InvalidArgumentException::invalidType('fingerprint as string or object that can be casted to string', $fingerprint); } $collection->add(new Fingerprint((string) $fingerprint)); } return $collection; }
public function __construct($filePath, $name, $passphrase = null) { if (!is_string($filePath)) { throw InvalidArgumentException::invalidType('string', $filePath); } if (!is_string($name)) { throw InvalidArgumentException::invalidType('string', $name); } if ($passphrase && !is_string($passphrase)) { throw InvalidArgumentException::invalidType('string', $passphrase); } $this->filePath = $filePath; $this->passphrase = $passphrase; $this->name = $name; }
/** * @param $file * * @return \DOMDocument */ public static function fromFile($file) { if (!is_string($file)) { throw InvalidArgumentException::invalidType('string', $file); } if (!is_file($file)) { throw new InvalidArgumentException(sprintf('Path "%s" is not a file', $file)); } if (!is_readable($file)) { throw new InvalidArgumentException(sprintf('File "%s" is not readable', $file)); } // libxml_disable_entity_loader(true) disables \DOMDocument::load() method // so we need to read the content and use \DOMDocument::loadXML() $xml = file_get_contents($file); if ($xml === false) { throw new RuntimeException(sprintf('Contents of readable file "%s" could not be gotten', $file)); } if (trim($xml) === '') { throw new RuntimeException(sprintf('File "%s" does not have content', $file)); } return static::fromString($xml); }
/** * Attempts to load a key based on the given certificateData * * @param string $certificateData */ public function loadCertificateData($certificateData) { if (!is_string($certificateData)) { throw InvalidArgumentException::invalidType('string', $certificateData); } $this->loadedKeys->add(X509::createFromCertificateData($certificateData)); }
/** * Asserts that the parameter is of type string * @param mixed $test * * @throws \Exception */ protected function assertIsString($test) { if (!is_string($test)) { throw InvalidArgumentException::invalidType('string', $test); } }