Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New encrypted socket API #21

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

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.

1 participant