Class: Sekret::Header

Inherits:
Object
  • Object
show all
Defined in:
lib/sekret/header.rb

Overview

Note:

You should never directly create a Header

A Payload header

Author:

  • Maddie Schipper

Since:

  • 1.0.0

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(authenticity, key, eiv, version, algorithm) ⇒ Header

Note:

You should never directly create a Payload

Create a new header

Since:

  • 1.0.0



51
52
53
54
55
56
57
# File 'lib/sekret/header.rb', line 51

def initialize(authenticity, key, eiv, version, algorithm)
  @authenticity = authenticity
  @key = key
  @iv = eiv
  @version = version
  @algorithm = algorithm
end

Instance Attribute Details

#algorithmString (readonly)

The encryption algorithm used to encrypt the body

Returns:

  • (String)

Since:

  • 1.0.0



39
40
41
# File 'lib/sekret/header.rb', line 39

def algorithm
  @algorithm
end

#authenticityString (readonly)

The authenticity token for the header

Returns:

  • (String)

Since:

  • 1.0.0



19
20
21
# File 'lib/sekret/header.rb', line 19

def authenticity
  @authenticity
end

#ivString (readonly)

The initialization vector used to encrypt the body

Returns:

  • (String)

Since:

  • 1.0.0



29
30
31
# File 'lib/sekret/header.rb', line 29

def iv
  @iv
end

#keyString (readonly)

The key used to encrypt the body

Returns:

  • (String)

Since:

  • 1.0.0



24
25
26
# File 'lib/sekret/header.rb', line 24

def key
  @key
end

#versionInteger (readonly)

The encryption version for the body

Returns:

  • (Integer)

Since:

  • 1.0.0



34
35
36
# File 'lib/sekret/header.rb', line 34

def version
  @version
end

Class Method Details

.from_decrypted(hash) ⇒ Object

Create a header from a decrypted hash

Since:

  • 1.0.0



63
64
65
66
67
68
69
70
71
# File 'lib/sekret/header.rb', line 63

def self.from_decrypted(hash)
  new(
    hash['aut'],
    Encoder.decode(hash['key']),
    Encoder.decode(hash['eiv']),
    hash['ver'],
    hash['alg']
  )
end

Instance Method Details

#to_hHash

Convert the header into it’s hash format

Returns:

  • (Hash)

Since:

  • 1.0.0



77
78
79
80
81
82
83
84
85
# File 'lib/sekret/header.rb', line 77

def to_h
  {
    aut: authenticity,
    key: Encoder.encode(key),
    eiv: Encoder.encode(iv),
    ver: version,
    alg: algorithm
  }
end

#to_sString

Convert the header into it’s string format

Returns:

  • (String)

Since:

  • 1.0.0



91
92
93
# File 'lib/sekret/header.rb', line 91

def to_s
  JSON.dump(to_h)
end