# OneLogin_Saml2_Utils

Utils of OneLogin PHP Toolkit

Defines several often used methods

### Methods

## Translates any string. Accepts args

    t(string $msg, array $args = array()) : string

static

### Arguments

#### $msg

`string`

Message to be translated

#### $args

`array`

Arguments

### Response

`string`

$translatedMsg Translated text

## This function attempts to validate an XML string against the specified schema.

    validateXML(string $xml, string $schema, boolean $debug = false) : string

static

It will parse the string into a DOM document and validate this document against the schema.

### Arguments

#### $xml

`string`

The XML string or document which should be validated.

#### $schema

`string`

The schema filename which should be used.

#### $debug

`boolean`

To disable/enable the debug mode

### Response

`string`

| DOMDocument $dom string that explains the problem or the DOMDocument

## Returns a x509 cert (adding header & footer if required).

    formatCert(string $cert, boolean $heads = true) : string

static

### Arguments

#### $cert

`string`

A x509 unformated cert

#### $heads

`boolean`

True if we want to include head and footer

### Response

`string`

$x509 Formated cert

## Returns a private key (adding header & footer if required).

    formatPrivateKey(string $key, boolean $heads = true) : string

static

### Arguments

#### $key

`string`

A private key

#### $heads

`boolean`

True if we want to include head and footer

### Response

`string`

$rsaKey Formated private key

## Executes a redirection to the provided url (or return the target url).

    redirect(string $url, array $parameters = array(), boolean $stay = false) : string

static

### Arguments

#### $url

`string`

The target url

#### $parameters

`array`

Extra parameters to be passed as part of the url

#### $stay

`boolean`

True if we want to stay (returns the url string) False to redirect

### Response

`string`

$url

## Returns the protocol + the current host + the port (if different than common ports).

    getSelfURLhost() : string

static

### Response

`string`

$url

## Returns the current host.

    getSelfHost() : string

static

### Response

`string`

$currentHost The current host

## Checks if https or http.

    isHTTPS() : boolean

static

### Response

`boolean`

$isHttps False if https is not active

## Returns the URL of the current host + current view.

    getSelfURLNoQuery() : string

static

### Response

`string`

## Returns the URL of the current host + current view + query.

    getSelfURL() : string

static

### Response

`string`

## Generates an unique string (used for example as ID for assertions).

    generateUniqueID() : string

static

### Response

`string`

A unique string

## Converts a UNIX timestamp to SAML2 timestamp on the form yyyy-mm-ddThh:mm:ss(\.s+)?Z.

    parseTime2SAML(string $time) : \$timestamp

static

### Arguments

#### $time

`string`

The time we should convert (DateTime).

### Response

`\$timestamp`

SAML2 timestamp.

## Converts a SAML2 timestamp on the form yyyy-mm-ddThh:mm:ss(\.s+)?Z to a UNIX timestamp. The sub-second part is ignored.

    parseSAML2Time(string $time) : \$timestamp

static

### Arguments

#### $time

`string`

The time we should convert (SAML Timestamp).

### Response

`\$timestamp`

Converted to a unix timestamp.

## Interprets a ISO8601 duration value relative to a given timestamp.

    parseDuration(string $duration, int $timestamp = null) : int

static

### Arguments

#### $duration

`string`

The duration, as a string.

#### $timestamp

`int`

The unix timestamp we should apply the

                         duration to. Optional, default to the
                         current time.

### Response

`int`

The new timestamp, after the duration is applied.

## Compares 2 dates and returns the earliest.

    getExpireTime(string $cacheDuration = null, string $validUntil = null) : int

static

### Arguments

#### $cacheDuration

`string`

The duration, as a string.

#### $validUntil

`string`

The valid until date, as a string or as a timestamp

### Response

`int`

$expireTime The expiration time.

## Extracts nodes from the DOMDocument.

    query(\DOMDocument $dom, string $query, \DomElement $context = null) : \DOMNodeList

static

### Arguments

#### $dom

`\DOMDocument`

The DOMDocument

#### $query

`string`

Xpath Expresion

#### $context

`\DomElement`

Context Node (DomElement)

### Response

`\DOMNodeList`

The queried nodes

## Checks if the session is started or not.

    isSessionStarted() : boolean

static

### Response

`boolean`

true if the sessíon is started

## Deletes the local session.

    deleteLocalSession()

static

## Calculates the fingerprint of a x509cert.

    calculateX509Fingerprint(string $x509cert) : string

static

### Arguments

#### $x509cert

`string`

x509 cert

### Response

`string`

Formated fingerprint

## Formates a fingerprint.

    formatFingerPrint(string $fingerprint) : string

static

### Arguments

#### $fingerprint

`string`

fingerprint

### Response

`string`

Formated fingerprint

## Generates a nameID.

    generateNameId(string $value, string $spnq, string $format, string $key = null) : string

static

### Arguments

#### $value

`string`

fingerprint

#### $spnq

`string`

SP Name Qualifier

#### $format

`string`

SP Format

#### $key

`string`

SP Key to encrypt the nameID

### Response

`string`

$nameIDElement DOMElement | XMLSec nameID

## Gets Status from a Response.

    getStatus(\DomElement $dom) : array

static

### Arguments

#### $dom

`\DomElement`

The Response as XML

### Response

`array`

$status The Status, an array with the code and a message.

## Decrypts an encrypted element.

    decryptElement(\DOMElement $encryptedData, \XMLSecurityKey $inputKey) : \DOMElement

static

### Arguments

#### $encryptedData

`\DOMElement`

The encrypted data.

#### $inputKey

`\XMLSecurityKey`

The decryption key.

### Response

`\DOMElement`

The decrypted element.

## Converts a XMLSecurityKey to the correct algorithm.

    castKey(XMLSecurityKey $key, $algorithm, $type = 'public')

static

### Arguments

#### $key

`XMLSecurityKey`

The key

#### $algorithm

`string`

The desired algorithm

#### $type

`string`

Public or private key, defaults to public.

## Adds signature key and senders certificate to an element (Message or Assertion).

    addSign(string|\DomDocument $xml, string $key, string $cert)

static

### Arguments

#### $xml

`string|\DomDocument`

The element we should sign

#### $key

`string`

The private key

#### $cert

`string`

The public

## Validates a signature (Message or Assertion).

    validateSign(string|\DomDocument $xml, string|null $cert = null, string|null $fingerprint = null)

static

### Arguments

#### $xml

`string|\DomDocument`

The element we should validate

#### $cert

`string|null`

The pubic cert

#### $fingerprint

`string|null`

The fingerprint of the public cert