Initial commit

This commit is contained in:
2024-09-13 14:11:34 +02:00
commit a14f7077bb
31 changed files with 1901 additions and 0 deletions

View File

@ -0,0 +1,15 @@
<?php
declare(strict_types=1);
namespace Pdahal\Xmpp\AuthTypes;
interface Authenticable
{
/**
* Based on auth type, return the right format of credentials to be sent to the server.
*/
public function encodedCredentials(): string;
public function getName(): string;
}

View File

@ -0,0 +1,24 @@
<?php
declare(strict_types=1);
namespace Pdahal\Xmpp\AuthTypes;
use Pdahal\Xmpp\Options;
use Pdahal\Xmpp\Xml\Xml;
abstract class Authentication implements Authenticable
{
use Xml;
protected string $name;
public function __construct(protected Options $options)
{
}
public function getName(): string
{
return $this->name;
}
}

View File

@ -0,0 +1,16 @@
<?php
declare(strict_types=1);
namespace Pdahal\Xmpp\AuthTypes;
class DigestMD5 extends Authentication
{
protected string $name = 'DIGEST-MD5';
public function encodedCredentials(): string
{
$credentials = "\x00{$this->options->getUsername()}\x00{$this->options->getPassword()}";
return self::quote(sha1($credentials));
}
}

16
src/AuthTypes/Plain.php Normal file
View File

@ -0,0 +1,16 @@
<?php
declare(strict_types=1);
namespace Pdahal\Xmpp\AuthTypes;
class Plain extends Authentication
{
protected string $name = 'PLAIN';
public function encodedCredentials(): string
{
$credentials = "\x00{$this->options->getUsername()}\x00{$this->options->getPassword()}";
return self::quote(base64_encode($credentials));
}
}