secrit 0.0.5 → 0.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/secrit.rb +37 -4
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ebe7a9abd529893db98b6ea4169e629418e6328210f57a3c84b953f960c15301
4
- data.tar.gz: bff251e6d9c4ebf773480d04d5b2b1a40a0895260bede6112260804b4fcee8d6
3
+ metadata.gz: f35a3d949ae58a5bbd6f8ca76e17d3ce71af0c3c4df348a2ce0a1ad4e59b79e0
4
+ data.tar.gz: 636d8ef6047de9594bb0959b6a53c6ef3ba2448107ed4405dd88c6c4718d0721
5
5
  SHA512:
6
- metadata.gz: 454260a665033b13a4e2de64ccd9d49642678b25aca857e1b9b40f8c82c988b9900f1ba361dd7e7fa7cc94dcc35843993695d4aaa591f603617b019ed0f227ad
7
- data.tar.gz: 4eecd853e9b0ced9a7029cfc81a1d0360662f7dcbc282112eed9c4608f862a9b6d9debd0a051d5efcc6102fe9001f9a19f818fc3093b6ea65cbb1581ca8b2a38
6
+ metadata.gz: 0f780a78061b2a16131ff1d9c082bbe280537deb87ac5b4f54de5d48fff884840270d7fcd909a83db0070b160c6677d310ae1f7f1dd929688cb03e77815a258e
7
+ data.tar.gz: ac5d0fbdd12a6fa0eb2fca6ff117d939c6cac89aca458b1a4cd0d5c4aa242c4b0ad05ec38320b8a316010498609ca8f78f13b004675bf5174718171cdc4644f2
data/lib/secrit.rb CHANGED
@@ -1,38 +1,63 @@
1
1
  #!/usr/bin/env ruby
2
2
  require 'gpgme'
3
3
 
4
- # Define an interface (or contract) for decryption
4
+ # Decryptor provides an interface for decryption. Classes that extend Decryptor
5
+ # must implement the decrypt method.
5
6
  class Decryptor
7
+ # Decrypts a file at the given path.
8
+ #
9
+ # @param file_path [String] the path to the file to be decrypted.
10
+ # @raise [NotImplementedError] if the method is called on the Decryptor class
11
+ # itself, rather than a subclass.
6
12
  def decrypt(file_path)
7
13
  raise NotImplementedError
8
14
  end
9
15
  end
10
16
 
11
- # Provide a default implementation
17
+ # GPGDecryptor is a default implementation of the Decryptor interface using GPG.
12
18
  class GPGDecryptor < Decryptor
19
+ # Decrypts a file at the given path using GPG.
20
+ #
21
+ # @param file_path [String] the path to the file to be decrypted.
22
+ # @return [GPGME::Data] the decrypted data.
13
23
  def decrypt(file_path)
14
24
  crypto = GPGME::Crypto.new
15
25
  decrypted_data = crypto.decrypt(File.open(file_path))
16
- #decrypted_data.to_s.strip
17
26
  decrypted_data
18
27
  end
19
28
  end
20
29
 
30
+ # Secrit provides methods to get encrypted data, allowing optional customization
31
+ # of the decryption process.
21
32
  class Secrit
22
33
  attr_accessor :storage
23
34
 
35
+ # Retrieves decrypted data for a given entry path.
36
+ #
37
+ # @param entry_path [String] the entry path to the encrypted data.
38
+ # @param storage [String] the storage path for the encrypted files (optional).
39
+ # @return [String] the decrypted content as a string.
24
40
  def self.get(entry_path, storage: nil)
25
41
  new(
26
42
  storage: storage
27
43
  ).get(entry_path).to_s.strip
28
44
  end
29
45
 
30
- # Allow optional injection of custom Decryptor
46
+ # Initializes a new Secrit object with optional customization.
47
+ #
48
+ # @param decryptor [Decryptor] an object that responds to the decrypt method
49
+ # (optional, defaults to GPGDecryptor.new).
50
+ # @param storage [String] the storage path for the encrypted files (optional).
31
51
  def initialize(decryptor: GPGDecryptor.new, storage: nil)
32
52
  @decryptor = decryptor
33
53
  @storage = storage || File.expand_path("~/.password-store/")
34
54
  end
35
55
 
56
+ # Retrieves decrypted data for a given entry path.
57
+ #
58
+ # @param entry_path [String] the entry path to the encrypted data.
59
+ # @return [GPGME::Data] the decrypted data.
60
+ # @raise [RuntimeError] if the file does not exist at the constructed path.
36
61
  def get(entry_path)
37
62
  full_path = construct_path(entry_path)
38
63
  validate_file_existence(full_path)
@@ -41,10 +66,18 @@ class Secrit
41
66
 
42
67
  private
43
68
 
69
+ # Constructs the full path to an encrypted file based on the entry path.
70
+ #
71
+ # @param entry_path [String] the entry path.
72
+ # @return [String] the full path to the encrypted file.
44
73
  def construct_path(entry_path)
45
74
  File.join(storage, "#{entry_path}.gpg")
46
75
  end
47
76
 
77
+ # Validates that a file exists at the given path.
78
+ #
79
+ # @param full_path [String] the full path to the file.
80
+ # @raise [RuntimeError] if the file does not exist at the given path.
48
81
  def validate_file_existence(full_path)
49
82
  raise "File not found: #{full_path}" unless File.exist?(full_path)
50
83
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: secrit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Simpthy
@@ -80,7 +80,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
80
80
  - !ruby/object:Gem::Version
81
81
  version: '0'
82
82
  requirements: []
83
- rubygems_version: 3.3.5
83
+ rubygems_version: 3.4.10
84
84
  signing_key:
85
85
  specification_version: 4
86
86
  summary: Password-Store (or 'pass') managed secrets in your Ruby