Skip to content

Commit b4cf36d

Browse files
committed
Add duration format as a constant
1 parent 5e8ad48 commit b4cf36d

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

lib/onelogin/ruby-saml/utils.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ class Utils
1515

1616
DSIG = "http://www.w3.org/2000/09/xmldsig#"
1717
XENC = "http://www.w3.org/2001/04/xmlenc#"
18+
DURATION_FORMAT = %r(^(-?)P(?:(?:(?:(\d+)Y)?(?:(\d+)M)?(?:(\d+)D)?(?:T(?:(\d+)H)?(?:(\d+)M)?(?:(\d+)S)?)?)|(?:(\d+)W))$)
1819

1920
# Checks if the x509 cert provided is expired
2021
#
@@ -38,7 +39,7 @@ def self.is_cert_expired(cert)
3839
# @return [Integer] The new timestamp, after the duration is applied.
3940
#
4041
def self.parse_duration(duration, timestamp=Time.now)
41-
matches = duration.match(/^(-?)P(?:(?:(?:(\d+)Y)?(?:(\d+)M)?(?:(\d+)D)?(?:T(?:(\d+)H)?(?:(\d+)M)?(?:(\d+)S)?)?)|(?:(\d+)W))$/)
42+
matches = duration.match(DURATION_FORMAT)
4243

4344
if matches.nil?
4445
raise Exception.new("Invalid ISO 8601 duration")

0 commit comments

Comments
 (0)