-
-
Notifications
You must be signed in to change notification settings - Fork 29
Add openssl support in univers #42
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -343,3 +343,173 @@ def __gt__(self, other): | |||||
| if not isinstance(other, self.__class__): | ||||||
| return NotImplemented | ||||||
| return gentoo.vercmp(self.value, other.value) > 0 | ||||||
|
|
||||||
|
|
||||||
| @attr.s(frozen=True, order=False, eq=False, hash=True) | ||||||
| class LegacyOpensslVersion(Version): | ||||||
|
keshav-space marked this conversation as resolved.
|
||||||
| """ | ||||||
| Represent an Legacy Openssl Version . | ||||||
|
|
||||||
| For example:: | ||||||
|
|
||||||
|
keshav-space marked this conversation as resolved.
Outdated
keshav-space marked this conversation as resolved.
Outdated
|
||||||
| # 1.0.1f|0.9.7d|1.0.2ac | ||||||
|
keshav-space marked this conversation as resolved.
Outdated
|
||||||
| """ | ||||||
|
|
||||||
| @classmethod | ||||||
| def is_valid(cls, string): | ||||||
| return bool(cls.parse(string)) | ||||||
|
|
||||||
| @classmethod | ||||||
| def parse(cls, string): | ||||||
|
|
||||||
|
keshav-space marked this conversation as resolved.
Outdated
|
||||||
| """ | ||||||
| Returns the tuple containig the 4 segments (i.e major, minor, build, patch) of Legacy Version, | ||||||
|
keshav-space marked this conversation as resolved.
Outdated
|
||||||
| False if not valid Legacy Openssl Version. | ||||||
|
|
||||||
| For example:: | ||||||
| >>> LegacyOpensslVersion.parse("1.0.1f") | ||||||
| (1, 0, 1, 'f') | ||||||
| >>> LegacyOpensslVersion.parse("1.0.2ac") | ||||||
| (1, 0, 2, 'ac') | ||||||
| >>> LegacyOpensslVersion.parse("2.0.2az") | ||||||
| False | ||||||
| """ | ||||||
|
keshav-space marked this conversation as resolved.
|
||||||
|
|
||||||
| # All legacy base version of openssl that ever exited/exists. | ||||||
|
keshav-space marked this conversation as resolved.
Outdated
|
||||||
| all_legacy_base = ( | ||||||
| "0.9.1", | ||||||
| "0.9.2", | ||||||
| "0.9.3", | ||||||
| "0.9.4", | ||||||
| "0.9.5", | ||||||
| "0.9.6", | ||||||
| "0.9.7", | ||||||
| "0.9.8", | ||||||
| "1.0.0", | ||||||
| "1.0.1", | ||||||
| "1.0.2", | ||||||
| "1.1.0", | ||||||
| "1.1.1", | ||||||
| ) | ||||||
| # check if starts with a valid base | ||||||
|
keshav-space marked this conversation as resolved.
Outdated
|
||||||
| if not string.startswith(all_legacy_base): | ||||||
| return False | ||||||
|
|
||||||
| segments = string.split(".") | ||||||
| if not len(segments) == 3: | ||||||
| return False | ||||||
| major, minor, build = segments | ||||||
| major = int(major) | ||||||
| minor = int(minor) | ||||||
| if build.isdigit(): | ||||||
| build = int(build) | ||||||
| patch = "" | ||||||
| else: | ||||||
| patch = build[1:] | ||||||
| build = int(build[0]) | ||||||
| if patch and patch[0].isdigit(): | ||||||
|
keshav-space marked this conversation as resolved.
Outdated
|
||||||
| return False | ||||||
| return major, minor, build, patch | ||||||
|
|
||||||
| @classmethod | ||||||
| def build_value(cls, string): | ||||||
| return cls.parse(string) | ||||||
|
|
||||||
| def __str__(self): | ||||||
| return self.normalized_string | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What about instead:
Suggested change
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seems more pragmatic...👍
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Won't work. >>> from univers.versions import LegacyOpensslVersion
>>> vers=LegacyOpensslVersion("1.0.2a")
>>> str(vers)
Traceback (most recent call last):
...
AttributeError: 'LegacyOpensslVersion' object has no attribute 'major'We can have something like this return f"{self.value[0]}.{self.value[1]}.{self.value[2]}{self.value[3]}" |
||||||
|
|
||||||
|
|
||||||
| @attr.s(frozen=True, order=False, eq=False, hash=True) | ||||||
| class OpensslVersion(Version): | ||||||
|
|
||||||
|
keshav-space marked this conversation as resolved.
Outdated
|
||||||
| """ | ||||||
| Internally tracks two types of openssl versions | ||||||
| - Legacy versions: Implemented in LegacyOpensslVersion | ||||||
|
keshav-space marked this conversation as resolved.
Outdated
|
||||||
| - New versions: Semver | ||||||
|
keshav-space marked this conversation as resolved.
Outdated
|
||||||
| For example:: | ||||||
| >>> old = OpensslVersion("1.1.0f") | ||||||
| >>> new = OpensslVersion("3.0.1") | ||||||
| >>> assert old == OpensslVersion(string="1.1.0f") | ||||||
| >>> assert new == OpensslVersion(string="3.0.1") | ||||||
| >>> assert old.value == LegacyOpensslVersion(string="1.1.0f") | ||||||
| >>> assert new.value == SemverVersion(string="3.0.1") | ||||||
| >>> OpensslVersion("1.2.4fg") | ||||||
| Traceback (most recent call last): | ||||||
| ... | ||||||
| univers.versions.InvalidVersion: '1.2.4fg' is not a valid <class 'univers.versions.OpensslVersion'> | ||||||
| """ | ||||||
|
keshav-space marked this conversation as resolved.
|
||||||
|
|
||||||
| @classmethod | ||||||
| def is_valid(cls, string): | ||||||
| return cls.is_valid_new(string) or cls.is_valid_legacy(string) | ||||||
|
|
||||||
| @classmethod | ||||||
| def build_value(cls, string): | ||||||
| """ | ||||||
| Return a wrapped version "value" object depending on | ||||||
| whether version is legacy or semver. | ||||||
| """ | ||||||
| if cls.is_valid_legacy(string): | ||||||
| return LegacyOpensslVersion(string) | ||||||
| if cls.is_valid_new(string): | ||||||
| return SemverVersion(string) | ||||||
|
|
||||||
| @classmethod | ||||||
| def is_valid_new(cls, string): | ||||||
| """ | ||||||
| Checks the validity of new Openssl Version. | ||||||
|
keshav-space marked this conversation as resolved.
Outdated
|
||||||
|
|
||||||
| For example:: | ||||||
| >>> OpensslVersion.is_valid_new("1.0.1f") | ||||||
| False | ||||||
| >>> OpensslVersion.is_valid_new("3.0.0") | ||||||
| True | ||||||
| >>> OpensslVersion.is_valid_new("3.0.2") | ||||||
| True | ||||||
| """ | ||||||
|
keshav-space marked this conversation as resolved.
|
||||||
| if SemverVersion.is_valid(string): | ||||||
| sem = semantic_version.Version.coerce(string) | ||||||
| return sem.major >= 3 | ||||||
|
|
||||||
| @classmethod | ||||||
| def is_valid_legacy(cls, string): | ||||||
| return LegacyOpensslVersion.is_valid(string) | ||||||
|
|
||||||
| def __eq__(self, other): | ||||||
|
keshav-space marked this conversation as resolved.
|
||||||
| if not isinstance(other, self.__class__): | ||||||
| return NotImplemented | ||||||
| if not isinstance(other.value, self.value.__class__): | ||||||
| return NotImplemented | ||||||
| return self.value.__eq__(other.value) | ||||||
|
|
||||||
| def __lt__(self, other): | ||||||
| if not isinstance(other, self.__class__): | ||||||
| return NotImplemented | ||||||
| if isinstance(other.value, self.value.__class__): | ||||||
| return self.value.__lt__(other.value) | ||||||
| # By construction legacy version is always behind Semver | ||||||
| return isinstance(self.value, LegacyOpensslVersion) | ||||||
|
|
||||||
| def __gt__(self, other): | ||||||
| if not isinstance(other, self.__class__): | ||||||
| return NotImplemented | ||||||
| if isinstance(other.value, self.value.__class__): | ||||||
| return self.value.__gt__(other.value) | ||||||
| # By construction semver version is always ahead of legacy | ||||||
| return isinstance(self.value, SemverVersion) | ||||||
|
|
||||||
| def __le__(self, other): | ||||||
| if not isinstance(other, self.__class__): | ||||||
| return NotImplemented | ||||||
| if isinstance(other.value, self.value.__class__): | ||||||
| return self.value.__le__(other.value) | ||||||
| # version value are of diff type, then legacy one is always behind semver | ||||||
| return isinstance(self.value, LegacyOpensslVersion) | ||||||
|
|
||||||
| def __ge__(self, other): | ||||||
| if not isinstance(other, self.__class__): | ||||||
| return NotImplemented | ||||||
| if isinstance(other.value, self.value.__class__): | ||||||
| return self.value.__ge__(other.value) | ||||||
| # version value are of diff type, then semver one is always ahead of legacy | ||||||
| return isinstance(self.value, SemverVersion) | ||||||
Uh oh!
There was an error while loading. Please reload this page.