-
-
Notifications
You must be signed in to change notification settings - Fork 886
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
Class constants #1160
Class constants #1160
Conversation
|
||
class SSH2_CHANNEL_EXTENDED_DATA_TYPE_CODES extends Enum | ||
{ | ||
const TTY_OP_END=0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here's how net\SSH2.php currently defines this:
$this->channel_extended_data_type_codes = [
1 => 'NET_SSH2_EXTENDED_DATA_STDERR'
];
phpseclib/Net/SSH2_DISCONNECT.php
Outdated
// RFC 5656 - Elliptic Curves (for curve25519-sha256@libssh.org) | ||
const KEX_ECDH_INIT = 30; | ||
const KEX_ECDH_REPLY = 31; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These should probably be defined in phpseclib/Net/SSH2_MSG.php
instead of SSH2_DISCONNECT.php
.
Also, I would say /these/ constants should be prefixed with SSH_ since they are in the SSH specs:
https://tools.ietf.org/html/rfc4254#section-9
Not all constants should be prefixed with SSH_. For example, the Terminal Codes shouldn't be since they're not in the SSH2 specs:
https://tools.ietf.org/html/rfc4254#section-8
But these I think should be.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Related to this.... I'm tentatively thinking that probably the disconnect reasons ought to be prefixed with SSH_DISCONNECT_
since that's how the RFC does it:
class SSH2_TERMINAL_MODES extends Enum | ||
{ | ||
const TTY_OP_END=0; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The class name (and constants defined therein) should probably be SSH2_CHANNEL_OPEN_FAILURE_REASONS lol.
It also looks like phpseclib only defines one of four possible reasons defined in https://tools.ietf.org/html/rfc4254#page-6
phpseclib/Common/Enum.php
Outdated
protected static function init() | ||
{ | ||
if (self::$constants==null) { | ||
$reflect = new \ReflectionClass(get_called_class()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like static::class
more than get_called_class()
personally :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Me too, but I try to keep php 5.3 compatibility. static::class - it's from 5.5.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The master branch (which this PR targets) only works on PHP 5.6+. Most significantly, every file in File/ASN1/Maps sets a class constant to an array, which wasn't possible until 5.6:
http://php.net/manual/en/migration56.new-features.php
A lot of the files also use constant expressions. The end result being that all of this greatly facilitates re-use.
phpseclib/Net/SSH2.php
Outdated
|
||
// $message_number = isset($this->message_numbers[ord($payload[0])]) ? $this->message_numbers[ord($payload[0])] : 'UNKNOWN (' . ord($payload[0]) . ')'; | ||
|
||
$messageText=(SSH2_MSG::valueExists(ord($payload[0])))?SSH2_MSG::name(ord($payload[0])):'UNKNOWN (' . ord($payload[0]) . ')'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this would be a cleaner way to write that:
$messageText = SSH2_MSG::valueExists(ord($payload[0])) ?
SSH2_MSG::name(ord($payload[0])) :
'UNKNOWN (' . ord($payload[0]) . ')';
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, thanks.
I like it! I made a few in-line comments. Here are a few more general thoughts:
|
Naming fix
use blah\blah\SSH_OPEN; if ( SSH_OPEN::ADMINISTRATIVELY_PROHIBITED ) and not use blah\blah\SSH\OPEN; if ( OPEN::ADMINISTRATIVELY_PROHIBITED ) In first case it looks almost like "real" constant.
|
Yah - it is cosmetic but none-the-less I prefer the second lol. That said, I just want to re-iterate that I do really like the idea :) |
BTW, if you're going to break BC, may be it's a good idea to kick out ssh1 support? |
Yah - that's the plan. |
As resume, you're refactoring a lot right now, so at this moment this patch is not relevant, but the idea is good. |
# Conflicts: # phpseclib/Net/SSH2.php
I am refactoring the master branch lots but right now my main focus is on getting ECDSA done. Honestly, I figure that could take a few months. ECDSA over prime fields seems pretty straight forward and there are lots of easy to understand reference implementations. ECDSA over binary fields otoh is more complicated. I guess I could forgo support for ECDSA over binary fields but I'm not ready to "give up" yet lol. After that I figure I'll completely revamp ASN1 / X509. That's liable to be another multi month long project. Honestly, I might not get around to revamping SSH2 this year I don't think it's realistic to expect you to be able to get back into this after taking that kind of break lol. I'd say: go ahead and pursue this and I'll merge it into master if you can get my suggestions implemented. If you can't (or don't want to lol) that's fine - it is a good idea and I can do it myself when the time comes for the refactor lol |
# Conflicts: # .gitignore # phpseclib/Net/SSH2.php
Proof of concept.
Use static classes constants instead of dynamically create global constants.
If it will work, I can do the same for other constants.