A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://docs.aws.amazon.com/sdkforruby/api/Aws/SNS/MessageVerifier.html below:

MessageVerifier — AWS SDK for Ruby V2

You are viewing documentation for version 2 of the AWS SDK for Ruby. Version 3 documentation can be found here.

Class: Aws::SNS::MessageVerifier
Inherits:
Object show all
Defined in:
aws-sdk-resources/lib/aws-sdk-resources/services/sns/message_verifier.rb
Overview

A utility class that can be used to verify the authenticity of messages sent by Amazon SNS.

verifier = Aws::SNS::MessageVerifier.new

verifier.authentic?(message_body)

verifier.authenticate!(message_body)

You can re-use a single MessageVerifier instance to authenticate multiple SNS messages.

Defined Under Namespace

Classes: VerificationError

Attribute Summary collapse Instance Method Summary collapse Constructor Details #initializeMessageVerifier

Returns a new instance of MessageVerifier.

42
43
44
# File 'aws-sdk-resources/lib/aws-sdk-resources/services/sns/message_verifier.rb', line 42

def initialize
  @cached_pems = {}
end
Instance Method Details #authentic?(message_body) ⇒ Boolean

Returns true if the given message has been successfully verified. Returns false otherwise.

49
50
51
52
53
# File 'aws-sdk-resources/lib/aws-sdk-resources/services/sns/message_verifier.rb', line 49

def authentic?(message_body)
  authenticate!(message_body)
rescue VerificationError
  false
end
#authenticate!(message_body) ⇒ Boolean

Returns true when the given message has been successfully verified.

60
61
62
63
64
65
66
67
68
69
# File 'aws-sdk-resources/lib/aws-sdk-resources/services/sns/message_verifier.rb', line 60

def authenticate!(message_body)
  msg = Json.load(message_body)
  msg = convert_lambda_msg(msg) if is_from_lambda(msg)
  if public_key(msg).verify(sha1, signature(msg), canonical_string(msg))
    true
  else
    msg = 'the authenticity of the message cannot be verified'
    raise VerificationError, msg
  end
end

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4