Module: VeracodeApiSigning::Validation
- Includes:
- Regions
- Included in:
- HMACAuth, Plugins::FaradayMiddleware
- Defined in:
- lib/veracode_api_signing/validation.rb
Constant Summary
Constants included from Regions
Instance Method Summary collapse
-
#valid_hex?(hex_string) ⇒ Boolean
True if valid hex, otherwise false.
- #validate_api_key_id(api_key_id) ⇒ Object
- #validate_api_key_secret(api_key_secret) ⇒ Object
-
#validate_scheme(scheme) ⇒ Boolean
True if valid scheme, otherwise raise error.
Methods included from Regions
#get_region_for_api_credential, #remove_prefix_from_api_credential
Instance Method Details
#valid_hex?(hex_string) ⇒ Boolean
Returns true if valid hex, otherwise false.
82 83 84 85 86 87 88 89 |
# File 'lib/veracode_api_signing/validation.rb', line 82 def valid_hex?(hex_string) hex_string = hex_string.to_s hex = true hex_string.chars.each do |digit| hex = false unless /[0-9A-Fa-f]/.match?(digit) end hex end |
#validate_api_key_id(api_key_id) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/veracode_api_signing/validation.rb', line 16 def validate_api_key_id(api_key_id) api_key_id_minimum_length = 32 api_key_id_maximum_length = 128 + 9 api_key_id_hex = remove_prefix_from_api_credential(api_key_id) if api_key_id.length < api_key_id_minimum_length raise VeracodeApiSigning::CredentialsError, "API key #{api_key_id} is #{api_key_id.length} characters, which is not long enough. The API key should be at least #{api_key_id_minimum_length} characters" end if api_key_id.length > api_key_id_maximum_length raise VeracodeApiSigning::CredentialsError, "API key #{api_key_id} is #{api_key_id.length} characters, which is too long. The API key should not be more than #{api_key_id_maximum_length} characters" end unless valid_hex?(api_key_id_hex) raise VeracodeApiSigning::CredentialsError, "API key #{api_key_id} does not seem to be hexadecimal" end end |
#validate_api_key_secret(api_key_secret) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/veracode_api_signing/validation.rb', line 41 def validate_api_key_secret(api_key_secret) secret_key_minimum_length = 128 secret_key_maximum_length = 1024 + 9 api_key_secret_hex = remove_prefix_from_api_credential(api_key_secret) if api_key_secret.length < secret_key_minimum_length raise VeracodeApiSigning::CredentialsError, "API secret key #{api_key_secret} is #{api_key_secret.length} characters, which is not long enough. The API secret key should be at least #{secret_key_minimum_length} characters" end if api_key_secret.length > secret_key_maximum_length raise VeracodeApiSigning::CredentialsError, "API secret key #{api_key_secret} is #{api_key_secret.length} characters, which is too long. The API secret key should not be more than #{secret_key_maximum_length} characters" end unless valid_hex?(api_key_secret_hex) raise VeracodeApiSigning::CredentialsError, "API secret key #{api_key_secret} does not seem to be hexadecimal" end end |
#validate_scheme(scheme) ⇒ Boolean
Returns true if valid scheme, otherwise raise error.
67 68 69 70 71 72 73 |
# File 'lib/veracode_api_signing/validation.rb', line 67 def validate_scheme(scheme) if scheme.casecmp("https").zero? true else raise VeracodeApiSigning::Exception, "Only HTTPS APIs are supported by Veracode." end end |