Class: Savvy::Cert::Certificate

Inherits:
Object
  • Object
show all
Defined in:
lib/savvy/cert/certificate.rb

Overview

Savvy Certificate

Author:

Since:

  • 0.1.0

Version:

  • 0.2

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(encoded_data) ⇒ Savvy::Cert::Certificate

A new instance of Certificate

Parameters:

  • encoded_data (String)

    the encoded Savvy certificate

Since:

  • 0.1.0


30
31
32
33
34
35
36
37
# File 'lib/savvy/cert/certificate.rb', line 30

def initialize(encoded_data)
  @encoded_data = encoded_data
  decoded = JSON.parse(Base64.strict_decode64(encoded_data), symbolize_names: true)
  @signed_by = decoded[:signed_by]
  @signed_on = Time.parse decoded[:signed_on] if decoded[:signed_on]
  @signature = decoded[:signature]
  @body = decoded[:certificate]
end

Instance Attribute Details

#bodyString | nil (readonly)

Returns the Base64 encoded encrypted certificate body

Returns:

  • (String | nil)

    the Base64 encoded encrypted certificate body

Since:

  • 0.1.0


23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/savvy/cert/certificate.rb', line 23

class Certificate
  attr_accessor :encoded_data
  attr_reader :signed_by, :signed_on, :signature, :body

  # A new instance of Certificate
  # @param encoded_data [String] the encoded Savvy certificate
  # @return [Savvy::Cert::Certificate] an instance of Certificate
  def initialize(encoded_data)
    @encoded_data = encoded_data
    decoded = JSON.parse(Base64.strict_decode64(encoded_data), symbolize_names: true)
    @signed_by = decoded[:signed_by]
    @signed_on = Time.parse decoded[:signed_on] if decoded[:signed_on]
    @signature = decoded[:signature]
    @body = decoded[:certificate]
  end

  # Generate a Savvy Certificate
  # @param signer [Savvy::Cert::Signer | MySignerClass] the certificate signer
  # @param client [Savvy::Cert::Client] a valid instance of Client
  # @example Generate a Savvy Certificate
  #   # create a client
  #   my_client = Client.new(name: 'My Awesome Application',
  #                          id: 'd58539ce114dfedf324fb1508e4db660',
  #                          secret: '64a6c90b9de9a85863eabaf828d123cc',
  #                          redirect_uri: 'https://my-awesome-app.com/oauth/callback',
  #                          agent: 'My Awesome Application/1.0.0',
  #                          version: '1.0.0')
  #   #=> <#Savvy::Cert::Client>
  #
  #   # create a signer
  #   my_signer = Signer.new(id: 'fe34a634-64c9-4333-93a5-f1728563603c',
  #                          private_key: '-----BEGIN RSA PRIVATE KEY-----\...')
  #   #=> #<Savvy::Cert::Signer>
  #
  #   # generate the certificate
  #   Certificate.generate(my_signer, my_client)
  #   #=> <#Savvy::Cert::Certificate>
  # @return [Savvy::Cert::Certificate] an instance of Certificate
  def self.generate(signer, client)
    return unless client.valid? && signer_valid?(signer)
    signed = signer.encrypt_and_sign(client.to_json)
    raw_cert = cert_json(signer.id, signed)
    new(Base64.strict_encode64(raw_cert))
  end

  # Validate a certificate was signed by a signer
  # @param signer [Savvy::Cert::Signer | MySignerClass] the signer to validate with
  # @example Validate a certificate signature
  #   certificate = Certificate.new("Zm9vIGJ...2E7a2xmag==")
  #   certificate.validate_signature(my_signer)
  #   #=> true
  # @return [Boolean] whether or not the signer signed the certificate
  def validate_signature(signer)
    return false unless signer_valid?(signer) && signature && body
    signer.validate_signature(signature, body)
  end

  # Read a certificate with a signer
  # @param signer [Savvy::Cert::Signer | MySignerClass] the signer to read the certificate with
  # @example Read certificate Data
  #   certificate = Certficiate.new("Zm9vIGJ...2E7a2xmag==")
  #   certificate.read_with(my_signer)
  #   #=> { name: 'My Awesome Application', id: 'd58539ce114dfedf324fb1508e4db660',... }
  # @return [Hash{Symbol => String} | nil] the decrypted client data of the certificate
  def read_with(signer)
    return unless validate_signature(signer)
    decrypted = signer.read(body)
    JSON.parse(decrypted, symbolize_names: true)
  end

  private_class_method def self.signer_valid?(signer)
    signer.respond_to?(:encrypt_and_sign) && signer.respond_to?(:id) &&
    signer.respond_to?(:validate_signature) && signer.respond_to?(:read)
  end

  private_class_method def self.cert_json(signer_id, signed)
    {
      signed_by: signer_id,
      signed_on: Time.now.utc,
      signature: signed[:signature],
      certificate: signed[:data]
    }.to_json
  end

  private

  def signer_valid?(signer)
    self.class.send(:signer_valid?, signer)
  end
end

#encoded_dataString

Returns the Base64 encoded certificate data

Returns:

  • (String)

    the Base64 encoded certificate data

Since:

  • 0.1.0


23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/savvy/cert/certificate.rb', line 23

class Certificate
  attr_accessor :encoded_data
  attr_reader :signed_by, :signed_on, :signature, :body

  # A new instance of Certificate
  # @param encoded_data [String] the encoded Savvy certificate
  # @return [Savvy::Cert::Certificate] an instance of Certificate
  def initialize(encoded_data)
    @encoded_data = encoded_data
    decoded = JSON.parse(Base64.strict_decode64(encoded_data), symbolize_names: true)
    @signed_by = decoded[:signed_by]
    @signed_on = Time.parse decoded[:signed_on] if decoded[:signed_on]
    @signature = decoded[:signature]
    @body = decoded[:certificate]
  end

  # Generate a Savvy Certificate
  # @param signer [Savvy::Cert::Signer | MySignerClass] the certificate signer
  # @param client [Savvy::Cert::Client] a valid instance of Client
  # @example Generate a Savvy Certificate
  #   # create a client
  #   my_client = Client.new(name: 'My Awesome Application',
  #                          id: 'd58539ce114dfedf324fb1508e4db660',
  #                          secret: '64a6c90b9de9a85863eabaf828d123cc',
  #                          redirect_uri: 'https://my-awesome-app.com/oauth/callback',
  #                          agent: 'My Awesome Application/1.0.0',
  #                          version: '1.0.0')
  #   #=> <#Savvy::Cert::Client>
  #
  #   # create a signer
  #   my_signer = Signer.new(id: 'fe34a634-64c9-4333-93a5-f1728563603c',
  #                          private_key: '-----BEGIN RSA PRIVATE KEY-----\...')
  #   #=> #<Savvy::Cert::Signer>
  #
  #   # generate the certificate
  #   Certificate.generate(my_signer, my_client)
  #   #=> <#Savvy::Cert::Certificate>
  # @return [Savvy::Cert::Certificate] an instance of Certificate
  def self.generate(signer, client)
    return unless client.valid? && signer_valid?(signer)
    signed = signer.encrypt_and_sign(client.to_json)
    raw_cert = cert_json(signer.id, signed)
    new(Base64.strict_encode64(raw_cert))
  end

  # Validate a certificate was signed by a signer
  # @param signer [Savvy::Cert::Signer | MySignerClass] the signer to validate with
  # @example Validate a certificate signature
  #   certificate = Certificate.new("Zm9vIGJ...2E7a2xmag==")
  #   certificate.validate_signature(my_signer)
  #   #=> true
  # @return [Boolean] whether or not the signer signed the certificate
  def validate_signature(signer)
    return false unless signer_valid?(signer) && signature && body
    signer.validate_signature(signature, body)
  end

  # Read a certificate with a signer
  # @param signer [Savvy::Cert::Signer | MySignerClass] the signer to read the certificate with
  # @example Read certificate Data
  #   certificate = Certficiate.new("Zm9vIGJ...2E7a2xmag==")
  #   certificate.read_with(my_signer)
  #   #=> { name: 'My Awesome Application', id: 'd58539ce114dfedf324fb1508e4db660',... }
  # @return [Hash{Symbol => String} | nil] the decrypted client data of the certificate
  def read_with(signer)
    return unless validate_signature(signer)
    decrypted = signer.read(body)
    JSON.parse(decrypted, symbolize_names: true)
  end

  private_class_method def self.signer_valid?(signer)
    signer.respond_to?(:encrypt_and_sign) && signer.respond_to?(:id) &&
    signer.respond_to?(:validate_signature) && signer.respond_to?(:read)
  end

  private_class_method def self.cert_json(signer_id, signed)
    {
      signed_by: signer_id,
      signed_on: Time.now.utc,
      signature: signed[:signature],
      certificate: signed[:data]
    }.to_json
  end

  private

  def signer_valid?(signer)
    self.class.send(:signer_valid?, signer)
  end
end

#signatureString | nil (readonly)

Returns the Base64 encoded signature of the certificate

Returns:

  • (String | nil)

    the Base64 encoded signature of the certificate

Since:

  • 0.1.0


23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/savvy/cert/certificate.rb', line 23

class Certificate
  attr_accessor :encoded_data
  attr_reader :signed_by, :signed_on, :signature, :body

  # A new instance of Certificate
  # @param encoded_data [String] the encoded Savvy certificate
  # @return [Savvy::Cert::Certificate] an instance of Certificate
  def initialize(encoded_data)
    @encoded_data = encoded_data
    decoded = JSON.parse(Base64.strict_decode64(encoded_data), symbolize_names: true)
    @signed_by = decoded[:signed_by]
    @signed_on = Time.parse decoded[:signed_on] if decoded[:signed_on]
    @signature = decoded[:signature]
    @body = decoded[:certificate]
  end

  # Generate a Savvy Certificate
  # @param signer [Savvy::Cert::Signer | MySignerClass] the certificate signer
  # @param client [Savvy::Cert::Client] a valid instance of Client
  # @example Generate a Savvy Certificate
  #   # create a client
  #   my_client = Client.new(name: 'My Awesome Application',
  #                          id: 'd58539ce114dfedf324fb1508e4db660',
  #                          secret: '64a6c90b9de9a85863eabaf828d123cc',
  #                          redirect_uri: 'https://my-awesome-app.com/oauth/callback',
  #                          agent: 'My Awesome Application/1.0.0',
  #                          version: '1.0.0')
  #   #=> <#Savvy::Cert::Client>
  #
  #   # create a signer
  #   my_signer = Signer.new(id: 'fe34a634-64c9-4333-93a5-f1728563603c',
  #                          private_key: '-----BEGIN RSA PRIVATE KEY-----\...')
  #   #=> #<Savvy::Cert::Signer>
  #
  #   # generate the certificate
  #   Certificate.generate(my_signer, my_client)
  #   #=> <#Savvy::Cert::Certificate>
  # @return [Savvy::Cert::Certificate] an instance of Certificate
  def self.generate(signer, client)
    return unless client.valid? && signer_valid?(signer)
    signed = signer.encrypt_and_sign(client.to_json)
    raw_cert = cert_json(signer.id, signed)
    new(Base64.strict_encode64(raw_cert))
  end

  # Validate a certificate was signed by a signer
  # @param signer [Savvy::Cert::Signer | MySignerClass] the signer to validate with
  # @example Validate a certificate signature
  #   certificate = Certificate.new("Zm9vIGJ...2E7a2xmag==")
  #   certificate.validate_signature(my_signer)
  #   #=> true
  # @return [Boolean] whether or not the signer signed the certificate
  def validate_signature(signer)
    return false unless signer_valid?(signer) && signature && body
    signer.validate_signature(signature, body)
  end

  # Read a certificate with a signer
  # @param signer [Savvy::Cert::Signer | MySignerClass] the signer to read the certificate with
  # @example Read certificate Data
  #   certificate = Certficiate.new("Zm9vIGJ...2E7a2xmag==")
  #   certificate.read_with(my_signer)
  #   #=> { name: 'My Awesome Application', id: 'd58539ce114dfedf324fb1508e4db660',... }
  # @return [Hash{Symbol => String} | nil] the decrypted client data of the certificate
  def read_with(signer)
    return unless validate_signature(signer)
    decrypted = signer.read(body)
    JSON.parse(decrypted, symbolize_names: true)
  end

  private_class_method def self.signer_valid?(signer)
    signer.respond_to?(:encrypt_and_sign) && signer.respond_to?(:id) &&
    signer.respond_to?(:validate_signature) && signer.respond_to?(:read)
  end

  private_class_method def self.cert_json(signer_id, signed)
    {
      signed_by: signer_id,
      signed_on: Time.now.utc,
      signature: signed[:signature],
      certificate: signed[:data]
    }.to_json
  end

  private

  def signer_valid?(signer)
    self.class.send(:signer_valid?, signer)
  end
end

#signed_bySting | Fixnum | nil (readonly)

Returns the signer identifier

Returns:

  • (Sting | Fixnum | nil)

    the signer identifier

Since:

  • 0.1.0


23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/savvy/cert/certificate.rb', line 23

class Certificate
  attr_accessor :encoded_data
  attr_reader :signed_by, :signed_on, :signature, :body

  # A new instance of Certificate
  # @param encoded_data [String] the encoded Savvy certificate
  # @return [Savvy::Cert::Certificate] an instance of Certificate
  def initialize(encoded_data)
    @encoded_data = encoded_data
    decoded = JSON.parse(Base64.strict_decode64(encoded_data), symbolize_names: true)
    @signed_by = decoded[:signed_by]
    @signed_on = Time.parse decoded[:signed_on] if decoded[:signed_on]
    @signature = decoded[:signature]
    @body = decoded[:certificate]
  end

  # Generate a Savvy Certificate
  # @param signer [Savvy::Cert::Signer | MySignerClass] the certificate signer
  # @param client [Savvy::Cert::Client] a valid instance of Client
  # @example Generate a Savvy Certificate
  #   # create a client
  #   my_client = Client.new(name: 'My Awesome Application',
  #                          id: 'd58539ce114dfedf324fb1508e4db660',
  #                          secret: '64a6c90b9de9a85863eabaf828d123cc',
  #                          redirect_uri: 'https://my-awesome-app.com/oauth/callback',
  #                          agent: 'My Awesome Application/1.0.0',
  #                          version: '1.0.0')
  #   #=> <#Savvy::Cert::Client>
  #
  #   # create a signer
  #   my_signer = Signer.new(id: 'fe34a634-64c9-4333-93a5-f1728563603c',
  #                          private_key: '-----BEGIN RSA PRIVATE KEY-----\...')
  #   #=> #<Savvy::Cert::Signer>
  #
  #   # generate the certificate
  #   Certificate.generate(my_signer, my_client)
  #   #=> <#Savvy::Cert::Certificate>
  # @return [Savvy::Cert::Certificate] an instance of Certificate
  def self.generate(signer, client)
    return unless client.valid? && signer_valid?(signer)
    signed = signer.encrypt_and_sign(client.to_json)
    raw_cert = cert_json(signer.id, signed)
    new(Base64.strict_encode64(raw_cert))
  end

  # Validate a certificate was signed by a signer
  # @param signer [Savvy::Cert::Signer | MySignerClass] the signer to validate with
  # @example Validate a certificate signature
  #   certificate = Certificate.new("Zm9vIGJ...2E7a2xmag==")
  #   certificate.validate_signature(my_signer)
  #   #=> true
  # @return [Boolean] whether or not the signer signed the certificate
  def validate_signature(signer)
    return false unless signer_valid?(signer) && signature && body
    signer.validate_signature(signature, body)
  end

  # Read a certificate with a signer
  # @param signer [Savvy::Cert::Signer | MySignerClass] the signer to read the certificate with
  # @example Read certificate Data
  #   certificate = Certficiate.new("Zm9vIGJ...2E7a2xmag==")
  #   certificate.read_with(my_signer)
  #   #=> { name: 'My Awesome Application', id: 'd58539ce114dfedf324fb1508e4db660',... }
  # @return [Hash{Symbol => String} | nil] the decrypted client data of the certificate
  def read_with(signer)
    return unless validate_signature(signer)
    decrypted = signer.read(body)
    JSON.parse(decrypted, symbolize_names: true)
  end

  private_class_method def self.signer_valid?(signer)
    signer.respond_to?(:encrypt_and_sign) && signer.respond_to?(:id) &&
    signer.respond_to?(:validate_signature) && signer.respond_to?(:read)
  end

  private_class_method def self.cert_json(signer_id, signed)
    {
      signed_by: signer_id,
      signed_on: Time.now.utc,
      signature: signed[:signature],
      certificate: signed[:data]
    }.to_json
  end

  private

  def signer_valid?(signer)
    self.class.send(:signer_valid?, signer)
  end
end

#signed_onTime | nil (readonly)

Returns the datetime the certificate was signed

Returns:

  • (Time | nil)

    the datetime the certificate was signed

Since:

  • 0.1.0


23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/savvy/cert/certificate.rb', line 23

class Certificate
  attr_accessor :encoded_data
  attr_reader :signed_by, :signed_on, :signature, :body

  # A new instance of Certificate
  # @param encoded_data [String] the encoded Savvy certificate
  # @return [Savvy::Cert::Certificate] an instance of Certificate
  def initialize(encoded_data)
    @encoded_data = encoded_data
    decoded = JSON.parse(Base64.strict_decode64(encoded_data), symbolize_names: true)
    @signed_by = decoded[:signed_by]
    @signed_on = Time.parse decoded[:signed_on] if decoded[:signed_on]
    @signature = decoded[:signature]
    @body = decoded[:certificate]
  end

  # Generate a Savvy Certificate
  # @param signer [Savvy::Cert::Signer | MySignerClass] the certificate signer
  # @param client [Savvy::Cert::Client] a valid instance of Client
  # @example Generate a Savvy Certificate
  #   # create a client
  #   my_client = Client.new(name: 'My Awesome Application',
  #                          id: 'd58539ce114dfedf324fb1508e4db660',
  #                          secret: '64a6c90b9de9a85863eabaf828d123cc',
  #                          redirect_uri: 'https://my-awesome-app.com/oauth/callback',
  #                          agent: 'My Awesome Application/1.0.0',
  #                          version: '1.0.0')
  #   #=> <#Savvy::Cert::Client>
  #
  #   # create a signer
  #   my_signer = Signer.new(id: 'fe34a634-64c9-4333-93a5-f1728563603c',
  #                          private_key: '-----BEGIN RSA PRIVATE KEY-----\...')
  #   #=> #<Savvy::Cert::Signer>
  #
  #   # generate the certificate
  #   Certificate.generate(my_signer, my_client)
  #   #=> <#Savvy::Cert::Certificate>
  # @return [Savvy::Cert::Certificate] an instance of Certificate
  def self.generate(signer, client)
    return unless client.valid? && signer_valid?(signer)
    signed = signer.encrypt_and_sign(client.to_json)
    raw_cert = cert_json(signer.id, signed)
    new(Base64.strict_encode64(raw_cert))
  end

  # Validate a certificate was signed by a signer
  # @param signer [Savvy::Cert::Signer | MySignerClass] the signer to validate with
  # @example Validate a certificate signature
  #   certificate = Certificate.new("Zm9vIGJ...2E7a2xmag==")
  #   certificate.validate_signature(my_signer)
  #   #=> true
  # @return [Boolean] whether or not the signer signed the certificate
  def validate_signature(signer)
    return false unless signer_valid?(signer) && signature && body
    signer.validate_signature(signature, body)
  end

  # Read a certificate with a signer
  # @param signer [Savvy::Cert::Signer | MySignerClass] the signer to read the certificate with
  # @example Read certificate Data
  #   certificate = Certficiate.new("Zm9vIGJ...2E7a2xmag==")
  #   certificate.read_with(my_signer)
  #   #=> { name: 'My Awesome Application', id: 'd58539ce114dfedf324fb1508e4db660',... }
  # @return [Hash{Symbol => String} | nil] the decrypted client data of the certificate
  def read_with(signer)
    return unless validate_signature(signer)
    decrypted = signer.read(body)
    JSON.parse(decrypted, symbolize_names: true)
  end

  private_class_method def self.signer_valid?(signer)
    signer.respond_to?(:encrypt_and_sign) && signer.respond_to?(:id) &&
    signer.respond_to?(:validate_signature) && signer.respond_to?(:read)
  end

  private_class_method def self.cert_json(signer_id, signed)
    {
      signed_by: signer_id,
      signed_on: Time.now.utc,
      signature: signed[:signature],
      certificate: signed[:data]
    }.to_json
  end

  private

  def signer_valid?(signer)
    self.class.send(:signer_valid?, signer)
  end
end

Class Method Details

.generate(signer, client) ⇒ Savvy::Cert::Certificate

Generate a Savvy Certificate

Examples:

Generate a Savvy Certificate

# create a client
my_client = Client.new(name: 'My Awesome Application',
                       id: 'd58539ce114dfedf324fb1508e4db660',
                       secret: '64a6c90b9de9a85863eabaf828d123cc',
                       redirect_uri: 'https://my-awesome-app.com/oauth/callback',
                       agent: 'My Awesome Application/1.0.0',
                       version: '1.0.0')
#=> <#Savvy::Cert::Client>

# create a signer
my_signer = Signer.new(id: 'fe34a634-64c9-4333-93a5-f1728563603c',
                       private_key: '-----BEGIN RSA PRIVATE KEY-----\...')
#=> #<Savvy::Cert::Signer>

# generate the certificate
Certificate.generate(my_signer, my_client)
#=> <#Savvy::Cert::Certificate>

Parameters:

Returns:

Since:

  • 0.1.0


61
62
63
64
65
66
# File 'lib/savvy/cert/certificate.rb', line 61

def self.generate(signer, client)
  return unless client.valid? && signer_valid?(signer)
  signed = signer.encrypt_and_sign(client.to_json)
  raw_cert = cert_json(signer.id, signed)
  new(Base64.strict_encode64(raw_cert))
end

Instance Method Details

#read_with(signer) ⇒ Hash{Symbol => String} | nil

Read a certificate with a signer

Examples:

Read certificate Data

certificate = Certficiate.new("Zm9vIGJ...2E7a2xmag==")
certificate.read_with(my_signer)
#=> { name: 'My Awesome Application', id: 'd58539ce114dfedf324fb1508e4db660',... }

Parameters:

Returns:

  • (Hash{Symbol => String} | nil)

    the decrypted client data of the certificate

Since:

  • 0.1.0


87
88
89
90
91
# File 'lib/savvy/cert/certificate.rb', line 87

def read_with(signer)
  return unless validate_signature(signer)
  decrypted = signer.read(body)
  JSON.parse(decrypted, symbolize_names: true)
end

#validate_signature(signer) ⇒ Boolean

Validate a certificate was signed by a signer

Examples:

Validate a certificate signature

certificate = Certificate.new("Zm9vIGJ...2E7a2xmag==")
certificate.validate_signature(my_signer)
#=> true

Parameters:

Returns:

  • (Boolean)

    whether or not the signer signed the certificate

Since:

  • 0.1.0


75
76
77
78
# File 'lib/savvy/cert/certificate.rb', line 75

def validate_signature(signer)
  return false unless signer_valid?(signer) && signature && body
  signer.validate_signature(signature, body)
end