You are here

public function XMLSecurityDSig::setCanonicalMethod in SAML SP 2.0 Single Sign On (SSO) - SAML Service Provider 7

Parameters

string $method:

Throws

Exception

File

includes/XMLSecurityKey.php, line 928

Class

XMLSecurityDSig

Code

public function setCanonicalMethod($method) {
  switch ($method) {
    case 'http://www.w3.org/TR/2001/REC-xml-c14n-20010315':
    case 'http://www.w3.org/TR/2001/REC-xml-c14n-20010315#WithComments':
    case 'http://www.w3.org/2001/10/xml-exc-c14n#':
    case 'http://www.w3.org/2001/10/xml-exc-c14n#WithComments':
      $this->canonicalMethod = $method;
      break;
    default:
      throw new Exception('Invalid Canonical Method');
  }
  if ($xpath = $this
    ->getXPathObj()) {
    $query = './' . $this->searchpfx . ':SignedInfo';
    $nodeset = $xpath
      ->query($query, $this->sigNode);
    if ($nodeset->length > 1) {
      throw new Exception("Invalid structure - Too many SignedInfo elements found");
    }
    if ($sinfo = $nodeset
      ->item(0)) {
      $query = './' . $this->searchpfx . 'CanonicalizationMethod';
      $nodeset = $xpath
        ->query($query, $sinfo);
      if (!($canonNode = $nodeset
        ->item(0))) {
        $canonNode = $this
          ->createNewSignNode('CanonicalizationMethod');
        $sinfo
          ->insertBefore($canonNode, $sinfo->firstChild);
      }
      $canonNode
        ->setAttribute('Algorithm', $this->canonicalMethod);
    }
  }
}