2020-04-04 06:11:33 +07:00
|
|
|
package utils
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
"regexp"
|
2021-07-22 10:52:37 +07:00
|
|
|
"strings"
|
2020-04-04 06:11:33 +07:00
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
2021-05-05 05:06:05 +07:00
|
|
|
const (
|
|
|
|
windows = "windows"
|
|
|
|
testStringInput = "abcdefghijkl"
|
|
|
|
|
|
|
|
// RFC3339Zero is the default value for time.Time.Unix().
|
|
|
|
RFC3339Zero = int64(-62135596800)
|
2020-04-04 06:11:33 +07:00
|
|
|
|
2021-05-05 05:06:05 +07:00
|
|
|
// TLS13 is the textual representation of TLS 1.3.
|
|
|
|
TLS13 = "1.3"
|
2020-04-21 04:03:38 +07:00
|
|
|
|
2021-05-05 05:06:05 +07:00
|
|
|
// TLS12 is the textual representation of TLS 1.2.
|
|
|
|
TLS12 = "1.2"
|
2020-04-21 04:03:38 +07:00
|
|
|
|
2021-05-05 05:06:05 +07:00
|
|
|
// TLS11 is the textual representation of TLS 1.1.
|
|
|
|
TLS11 = "1.1"
|
2020-04-21 04:03:38 +07:00
|
|
|
|
2021-05-05 05:06:05 +07:00
|
|
|
// TLS10 is the textual representation of TLS 1.0.
|
|
|
|
TLS10 = "1.0"
|
2020-04-21 04:03:38 +07:00
|
|
|
|
2021-08-05 11:17:07 +07:00
|
|
|
clean = "clean"
|
|
|
|
tagged = "tagged"
|
|
|
|
unknown = "unknown"
|
|
|
|
)
|
|
|
|
|
2022-06-27 15:27:57 +07:00
|
|
|
// X.509 consts.
|
|
|
|
const (
|
|
|
|
BlockTypeRSAPrivateKey = "RSA PRIVATE KEY"
|
|
|
|
BlockTypeRSAPublicKey = "RSA PUBLIC KEY"
|
|
|
|
BlockTypeECDSAPrivateKey = "EC PRIVATE KEY"
|
|
|
|
BlockTypePKCS8PrivateKey = "PRIVATE KEY"
|
|
|
|
BlockTypePKIXPublicKey = "PUBLIC KEY"
|
|
|
|
BlockTypeCertificate = "CERTIFICATE"
|
|
|
|
BlockTypeCertificateRequest = "CERTIFICATE REQUEST"
|
|
|
|
|
|
|
|
KeyAlgorithmRSA = "RSA"
|
|
|
|
KeyAlgorithmECDSA = "ECDSA"
|
|
|
|
KeyAlgorithmEd25519 = "ED25519"
|
|
|
|
|
|
|
|
HashAlgorithmSHA1 = "SHA1"
|
|
|
|
HashAlgorithmSHA256 = "SHA256"
|
|
|
|
HashAlgorithmSHA384 = "SHA384"
|
|
|
|
HashAlgorithmSHA512 = "SHA512"
|
|
|
|
|
|
|
|
EllipticCurveP224 = "P224"
|
|
|
|
EllipticCurveP256 = "P256"
|
|
|
|
EllipticCurveP384 = "P384"
|
|
|
|
EllipticCurveP521 = "P521"
|
|
|
|
|
|
|
|
EllipticCurveAltP224 = "P-224"
|
|
|
|
EllipticCurveAltP256 = "P-256"
|
|
|
|
EllipticCurveAltP384 = "P-384"
|
|
|
|
EllipticCurveAltP521 = "P-521"
|
|
|
|
)
|
|
|
|
|
2021-08-05 11:17:07 +07:00
|
|
|
const (
|
2021-05-05 05:06:05 +07:00
|
|
|
// Hour is an int based representation of the time unit.
|
2022-07-23 04:59:14 +07:00
|
|
|
Hour = time.Minute * 60
|
2020-05-02 23:20:40 +07:00
|
|
|
|
2021-05-05 05:06:05 +07:00
|
|
|
// Day is an int based representation of the time unit.
|
|
|
|
Day = Hour * 24
|
2021-03-22 16:04:09 +07:00
|
|
|
|
2021-05-05 05:06:05 +07:00
|
|
|
// Week is an int based representation of the time unit.
|
|
|
|
Week = Day * 7
|
|
|
|
|
|
|
|
// Year is an int based representation of the time unit.
|
|
|
|
Year = Day * 365
|
|
|
|
|
|
|
|
// Month is an int based representation of the time unit.
|
|
|
|
Month = Year / 12
|
2021-08-05 11:17:07 +07:00
|
|
|
)
|
2021-06-18 11:35:43 +07:00
|
|
|
|
2021-08-05 11:17:07 +07:00
|
|
|
const (
|
2021-08-03 16:55:21 +07:00
|
|
|
errFmtLinuxNotFound = "open %s: no such file or directory"
|
2021-05-05 05:06:05 +07:00
|
|
|
)
|
2020-05-05 02:39:25 +07:00
|
|
|
|
2021-08-02 18:55:30 +07:00
|
|
|
var (
|
2022-03-02 13:40:26 +07:00
|
|
|
standardDurationUnits = []string{"ns", "us", "µs", "μs", "ms", "s", "m", "h"}
|
|
|
|
reDurationSeconds = regexp.MustCompile(`^\d+$`)
|
|
|
|
reDurationStandard = regexp.MustCompile(`(?P<Duration>[1-9]\d*?)(?P<Unit>[^\d\s]+)`)
|
|
|
|
)
|
|
|
|
|
|
|
|
// Duration unit types.
|
|
|
|
const (
|
|
|
|
DurationUnitDays = "d"
|
|
|
|
DurationUnitWeeks = "w"
|
|
|
|
DurationUnitMonths = "M"
|
|
|
|
DurationUnitYears = "y"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Number of hours in particular measurements of time.
|
|
|
|
const (
|
|
|
|
HoursInDay = 24
|
|
|
|
HoursInWeek = HoursInDay * 7
|
|
|
|
HoursInMonth = HoursInDay * 30
|
|
|
|
HoursInYear = HoursInDay * 365
|
2021-08-02 18:55:30 +07:00
|
|
|
)
|
2020-08-21 09:16:23 +07:00
|
|
|
|
2021-11-11 16:13:32 +07:00
|
|
|
var (
|
|
|
|
// AlphaNumericCharacters are literally just valid alphanumeric chars.
|
|
|
|
AlphaNumericCharacters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
|
|
|
|
)
|
2020-12-03 12:23:52 +07:00
|
|
|
|
2021-07-22 10:52:37 +07:00
|
|
|
var htmlEscaper = strings.NewReplacer(
|
|
|
|
"&", "&",
|
|
|
|
"<", "<",
|
|
|
|
">", ">",
|
|
|
|
`"`, """,
|
|
|
|
"'", "'",
|
|
|
|
)
|
2021-08-02 18:55:30 +07:00
|
|
|
|
|
|
|
// ErrTimeoutReached error thrown when a timeout is reached.
|
|
|
|
var ErrTimeoutReached = errors.New("timeout reached")
|
|
|
|
|
|
|
|
// ErrTLSVersionNotSupported returned when an unknown TLS version supplied.
|
2022-02-28 10:15:01 +07:00
|
|
|
var ErrTLSVersionNotSupported = errors.New("supplied tls version isn't supported")
|