scrubber_rb 0.1.0

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.
@@ -0,0 +1,150 @@
1
+ # Type signatures for scrubber_rb.
2
+
3
+ module Scrubber
4
+ VERSION: String
5
+
6
+ # Detector keys, sourced from the Rust registry at load time.
7
+ DEFAULTS: Array[Symbol]
8
+ INDIA: Array[Symbol]
9
+ ALL: Array[Symbol]
10
+
11
+ type detector = Symbol | String
12
+ type replacement = :label | :mask | :hash | :remove
13
+ type custom_patterns = Hash[Symbol | String, Regexp]
14
+
15
+ class Error < StandardError
16
+ end
17
+
18
+ # Raised when a detector key is not in the registry.
19
+ class UnknownDetectorError < Error
20
+ end
21
+
22
+ # Raised at construction time when a custom Regexp needs backtracking.
23
+ class UnsupportedPatternError < Error
24
+ end
25
+
26
+ # Raised for an invalid replacement strategy or malformed options.
27
+ class ConfigurationError < Error
28
+ end
29
+
30
+ # Raised when a panic is caught at the FFI boundary. Always a bug.
31
+ class InternalError < Error
32
+ end
33
+
34
+ class Match < Struct[untyped]
35
+ attr_accessor type: Symbol
36
+ attr_accessor begin: Integer
37
+ attr_accessor end: Integer
38
+ attr_accessor preview: String
39
+
40
+ def to_range: () -> Range[Integer]
41
+ def length: () -> Integer
42
+ end
43
+
44
+ # The compiled engine. Frozen; safe to share across threads.
45
+ class Instance
46
+ REPLACEMENTS: Array[Symbol]
47
+ CHUNK_SIZE: Integer
48
+ CARRY_SIZE: Integer
49
+
50
+ attr_reader detectors: Array[Symbol]
51
+ attr_reader custom: custom_patterns
52
+ attr_reader replacement: Symbol
53
+ attr_reader hash_salt: String?
54
+
55
+ def initialize: (
56
+ ?detectors: Array[detector],
57
+ ?custom: custom_patterns,
58
+ ?replacement: replacement | String,
59
+ ?hash_salt: String?
60
+ ) -> void
61
+
62
+ def scrub: (String | _ToStr) -> String
63
+ def scrub!: (String) -> String
64
+ def detect: (String | _ToStr) -> Array[Match]
65
+ def match?: (String | _ToStr) -> bool
66
+ def scrub_file: (String | ::Pathname, String | ::Pathname, ?chunk_size: Integer) -> Integer
67
+ def rule_count: () -> Integer
68
+ def cache_key: () -> Array[untyped]
69
+
70
+ def self.cache_key: (
71
+ detectors: Array[detector],
72
+ custom: custom_patterns,
73
+ replacement: replacement | String,
74
+ hash_salt: String?
75
+ ) -> Array[untyped]
76
+ end
77
+
78
+ # Wraps a Logger formatter and redacts its output.
79
+ class LogFormatter
80
+ attr_reader scrubber: Instance
81
+
82
+ def initialize: (?untyped formatter, ?scrubber: Instance?, **untyped) -> void
83
+ def call: (String severity, Time time, untyped progname, untyped msg) -> untyped
84
+ def self.default_formatter: () -> untyped
85
+ end
86
+
87
+ # Rack middleware. Non-destructive: publishes redacted copies at env["scrubber.*"].
88
+ class Middleware
89
+ QUERY_STRING: String
90
+ ENV_QUERY: String
91
+ ENV_PARAMS: String
92
+ ENV_INSTANCE: String
93
+
94
+ attr_reader scrubber: Instance
95
+
96
+ def initialize: (
97
+ untyped app,
98
+ ?scrubber: Instance?,
99
+ ?scrub_exceptions: bool,
100
+ **untyped
101
+ ) -> void
102
+ def call: (Hash[String, untyped] env) -> untyped
103
+ end
104
+
105
+ # Redacts prompts before they reach a model API.
106
+ class LLMGuard
107
+ CONTENT_KEYS: Array[String]
108
+
109
+ attr_reader scrubber: Instance
110
+
111
+ def initialize: (?scrubber: Instance?, ?replacement: replacement, **untyped) -> void
112
+ def call: (untyped) -> untyped
113
+ alias scrub call
114
+ def to_proc: () -> Proc
115
+ def findings: (untyped) -> Array[Match]
116
+ end
117
+
118
+ # The native extension. Not a public API; use Scrubber::Instance.
119
+ class Native
120
+ def self.new: (
121
+ Array[String] detectors,
122
+ Array[[String, String, Integer]] customs,
123
+ String replacement,
124
+ String? hash_salt
125
+ ) -> Native
126
+
127
+ def self.default_detectors: () -> Array[String]
128
+ def self.india_detectors: () -> Array[String]
129
+ def self.all_detectors: () -> Array[String]
130
+
131
+ def scrub: (String) -> String?
132
+ def detect: (String, bool) -> Array[[String, Integer, Integer, String]]
133
+ def rule_count: () -> Integer
134
+ end
135
+
136
+ def self.new: (
137
+ ?detectors: Array[detector],
138
+ ?custom: custom_patterns,
139
+ ?replacement: replacement | String,
140
+ ?hash_salt: String?
141
+ ) -> Instance
142
+
143
+ def self.scrub: (String | _ToStr, **untyped) -> String
144
+ def self.scrub!: (String, **untyped) -> String
145
+ def self.detect: (String | _ToStr, **untyped) -> Array[Match]
146
+ def self.match?: (String | _ToStr, **untyped) -> bool
147
+ def self.scrub_file: (String | ::Pathname, String | ::Pathname, **untyped) -> Integer
148
+ def self.engine: (**untyped) -> Instance
149
+ def self.reset!: () -> nil
150
+ end
metadata ADDED
@@ -0,0 +1,96 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: scrubber_rb
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Nikhil Nelson
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2026-08-16 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rb_sys
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.9.91
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.9.91
27
+ description: Redact emails, phone numbers, credit cards, SSNs, IBANs, IPs, JWTs, API
28
+ keys, private keys and Indian IDs (Aadhaar/PAN/UPI) from any string in a single
29
+ pass through a Rust engine. Checksum-validated (Luhn, Verhoeff, mod-97) so random
30
+ numbers are not mistaken for card numbers, and ReDoS-immune by construction. Ships
31
+ a Rails log formatter, Rack middleware and an LLM prompt guard.
32
+ email:
33
+ - thesolohacker47@gmail.com
34
+ executables: []
35
+ extensions:
36
+ - ext/scrubber_rb/extconf.rb
37
+ extra_rdoc_files: []
38
+ files:
39
+ - ".cargo/config.toml"
40
+ - CHANGELOG.md
41
+ - Cargo.lock
42
+ - Cargo.toml
43
+ - LICENSE
44
+ - README.md
45
+ - SECURITY.md
46
+ - ext/scrubber_rb/Cargo.toml
47
+ - ext/scrubber_rb/build.rs
48
+ - ext/scrubber_rb/extconf.rb
49
+ - ext/scrubber_rb/src/detectors/checksum.rs
50
+ - ext/scrubber_rb/src/detectors/mod.rs
51
+ - ext/scrubber_rb/src/detectors/upi.rs
52
+ - ext/scrubber_rb/src/detectors/validate.rs
53
+ - ext/scrubber_rb/src/engine.rs
54
+ - ext/scrubber_rb/src/lib.rs
55
+ - ext/scrubber_rb/src/nogvl.rs
56
+ - ext/scrubber_rb/src/offsets.rs
57
+ - ext/scrubber_rb/src/pattern.rs
58
+ - ext/scrubber_rb/src/replace.rs
59
+ - lib/scrubber/instance.rb
60
+ - lib/scrubber/llm_guard.rb
61
+ - lib/scrubber/log_formatter.rb
62
+ - lib/scrubber/match.rb
63
+ - lib/scrubber/middleware.rb
64
+ - lib/scrubber/version.rb
65
+ - lib/scrubber_rb.rb
66
+ - sig/scrubber_rb.rbs
67
+ homepage: https://github.com/TheSoloHacker47/scrubber-rb
68
+ licenses:
69
+ - MIT
70
+ metadata:
71
+ homepage_uri: https://github.com/TheSoloHacker47/scrubber-rb
72
+ source_code_uri: https://github.com/TheSoloHacker47/scrubber-rb
73
+ bug_tracker_uri: https://github.com/TheSoloHacker47/scrubber-rb/issues
74
+ changelog_uri: https://github.com/TheSoloHacker47/scrubber-rb/blob/main/CHANGELOG.md
75
+ documentation_uri: https://github.com/TheSoloHacker47/scrubber-rb#readme
76
+ rubygems_mfa_required: 'true'
77
+ post_install_message:
78
+ rdoc_options: []
79
+ require_paths:
80
+ - lib
81
+ required_ruby_version: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ version: 3.1.0
86
+ required_rubygems_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: 3.3.11
91
+ requirements: []
92
+ rubygems_version: 3.5.22
93
+ signing_key:
94
+ specification_version: 4
95
+ summary: Fast PII and secret redaction for Ruby, with a Rust core.
96
+ test_files: []