2020-08-01 23:59:20 +00:00
|
|
|
package xkeypairs
|
2020-07-25 09:13:19 +00:00
|
|
|
|
2020-08-01 07:32:17 +00:00
|
|
|
import (
|
|
|
|
"strconv"
|
|
|
|
|
|
|
|
"git.rootprojects.org/root/keypairs"
|
|
|
|
)
|
|
|
|
|
2020-08-01 23:59:20 +00:00
|
|
|
// ParsePEMPrivateKey will parse a PEM Private Key (or JWK or DER) but in future versions will fail to parse other key input types
|
2020-08-01 07:32:17 +00:00
|
|
|
func ParsePEMPrivateKey(block []byte) (keypairs.PrivateKey, error) {
|
|
|
|
// TODO do not parse DER or JWK
|
|
|
|
return keypairs.ParsePrivateKey(block)
|
|
|
|
}
|
2020-07-25 09:13:19 +00:00
|
|
|
|
2020-08-01 23:59:20 +00:00
|
|
|
func ParseDuration(exp string) (int, error) {
|
2020-07-25 09:13:19 +00:00
|
|
|
if "" == exp {
|
|
|
|
exp = "15m"
|
|
|
|
}
|
2020-08-04 07:09:43 +00:00
|
|
|
|
2020-07-25 09:13:19 +00:00
|
|
|
mult := 1
|
|
|
|
switch exp[len(exp)-1] {
|
|
|
|
case 'w':
|
|
|
|
mult *= 7
|
|
|
|
fallthrough
|
|
|
|
case 'd':
|
|
|
|
mult *= 24
|
|
|
|
fallthrough
|
|
|
|
case 'h':
|
|
|
|
mult *= 60
|
|
|
|
fallthrough
|
|
|
|
case 'm':
|
|
|
|
mult *= 60
|
|
|
|
fallthrough
|
|
|
|
case 's':
|
|
|
|
// no fallthrough
|
|
|
|
default:
|
|
|
|
// could be 'k' or 'z', but we assume its empty
|
|
|
|
exp += "s"
|
|
|
|
}
|
|
|
|
|
2020-08-04 07:09:43 +00:00
|
|
|
// 15m => num=15, mult=1*60
|
2020-07-25 09:13:19 +00:00
|
|
|
num, err := strconv.Atoi(exp[:len(exp)-1])
|
|
|
|
if nil != err {
|
|
|
|
return 0, err
|
|
|
|
}
|
2020-08-04 07:09:43 +00:00
|
|
|
|
2020-07-25 09:13:19 +00:00
|
|
|
return num * mult, nil
|
|
|
|
}
|