Skip to content

Conversation

@thekid
Copy link
Member

@thekid thekid commented Feb 26, 2022

This pull request deprecates the CryptoSocket class and its two implementations, SSLSocket and TLSSocket, in favor of a new class peer.EncryptedSocket, combining all of the functionality into one class.

Old code

use peer\{SSLSocket, TLSSocket};

// TLSSocket's constructor won't let us set the method directly,
// modify the base class' public member instead (!)
$newTLSSocket= function($host, $port, $method) {
  $s= new TLSSocket($host, $port);
  $s->cryptoImpl= $method;
  return $s;
};

$socket= match ($method) {
  'ssl'    => new SSLSocket($host, $port),
  'sslv2'  => new SSLSocket($host, $port, null, 2),
  'sslv3'  => new SSLSocket($host, $port, null, 3),
  'tls'    => new TLSSocket($host, $port),
  'tlsv10' => $newTLSSocket($host, $port, STREAM_CRYPTO_METHOD_TLSv1_0_CLIENT),
  'tlsv11' => // ...shortened for brevity
  default  => throw new IllegalArgumentException('Unknown crypto method '.$method),
};

New code

use peer\EncryptedSocket;

$socket= new EncryptedSocket($host, $port, null, $method);

@thekid thekid changed the title New encrypted sockert API New encrypted socket API Feb 26, 2022
@thekid
Copy link
Member Author

thekid commented Feb 26, 2022

Alternatively, we could add a method encrypt() to the base class

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants