permitplane-client 0.1.0.alpha.1-x64-mingw-ucrt

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,90 @@
1
+ # frozen_string_literal: true
2
+
3
+ module PermitPlane
4
+ # Process-wide convenience facade for ordinary feature checks.
5
+ module PPLicense
6
+ @pid = Process.pid
7
+ @mutex = Mutex.new
8
+
9
+ class << self
10
+ def configure(config: nil, config_path: nil, app_dir: nil, **client_options)
11
+ guard!
12
+ unless [config, config_path, app_dir].count { |value| !value.nil? } == 1
13
+ raise ArgumentError, "choose config, config_path, or app_dir"
14
+ end
15
+ @mutex.synchronize do
16
+ raise LifecycleError, "Close PermitPlane::PPLicense before configuring again" if @client
17
+
18
+ config_path = File.join(Native.absolute_path(app_dir), "permitplane.json") if app_dir
19
+ config = Client.read_config(config_path) if config_path
20
+ Thread.handle_interrupt(Exception => :never) do
21
+ @client = Client.new(config, **client_options)
22
+ end
23
+ end
24
+ nil
25
+ end
26
+
27
+ def is_licensed(feature)
28
+ with_client do |client|
29
+ if client.status.fetch("refresh_in_seconds") == 0
30
+ begin
31
+ client.refresh
32
+ rescue Error
33
+ # The native snapshot retains any rights that survived the failure.
34
+ end
35
+ end
36
+ client.has_feature(feature)
37
+ end || false
38
+ rescue StandardError
39
+ false
40
+ end
41
+
42
+ def is_licensed_async(feature)
43
+ guard!
44
+ Thread.new { is_licensed(feature) }
45
+ end
46
+
47
+ def status
48
+ with_client(&:status)
49
+ end
50
+
51
+ def activate_with_key(key, device_name: nil)
52
+ with_client { |client| client.activate_with_key(key, device_name: device_name) }
53
+ end
54
+
55
+ def close
56
+ guard!
57
+ @mutex.synchronize do
58
+ Thread.handle_interrupt(Exception => :never) do
59
+ if @client
60
+ begin
61
+ @client.persist
62
+ ensure
63
+ @client.close
64
+ @client = nil
65
+ end
66
+ end
67
+ end
68
+ end
69
+ nil
70
+ end
71
+
72
+ private
73
+
74
+ def with_client
75
+ guard!
76
+ @mutex.synchronize do
77
+ raise LifecycleError, "Configure PermitPlane::PPLicense first" unless @client
78
+
79
+ yield @client
80
+ end
81
+ end
82
+
83
+ def guard!
84
+ raise LifecycleError, "Use a new PermitPlane client after fork" unless @pid == Process.pid
85
+
86
+ Client.check_callback!
87
+ end
88
+ end
89
+ end
90
+ end
@@ -0,0 +1,223 @@
1
+ # frozen_string_literal: true
2
+
3
+ module PermitPlane
4
+ # Independent verification using the same native core as Client.
5
+ class Verification
6
+ def initialize(library_path: nil)
7
+ Client.check_callback!
8
+ @native = Native.new(library_path)
9
+ end
10
+
11
+ def normalize_key(input)
12
+ @native.output(:license_key_normalize, Native.text(input))
13
+ end
14
+
15
+ def thumbprint(public_key)
16
+ @native.output(:thumbprint, Native.bytes(public_key, 64))
17
+ end
18
+
19
+ def verify_grant(keys, token, context, &block)
20
+ verify(:grant, keys, [Native.text(token), Native.json(context)], &block)
21
+ end
22
+
23
+ def verify_license_file(keys, text, context, &block)
24
+ file = Native.text(text, max: 16_384)
25
+ verify(:license_file, keys, [file, file.bytesize, Native.json(context)], &block)
26
+ end
27
+
28
+ def replay_set
29
+ raise ArgumentError, "a block is required" unless block_given?
30
+
31
+ with_record(:replay_set, []) { |set| yield set }
32
+ end
33
+
34
+ def build_proof(public_key, method:, url:, issued_at:, nonce:, access_token: nil, jti: nil, &signer)
35
+ Client.check_callback!
36
+ raise ArgumentError, "a signing block is required" unless signer
37
+
38
+ closure = Native.callback([Native::P, Native::P, Native::P]) do |digest, output|
39
+ input = digest[0, 32]
40
+ signature = Native.invoke_host { Native.bytes(signer.call(input), 64) }
41
+ output[0, 64] = signature
42
+ 0
43
+ end
44
+ Thread.handle_interrupt(Exception => :never) do
45
+ @native.output(:proof_build, Native.bytes(public_key, 64), closure.to_i, nil,
46
+ Native.text(method, max: 16), Native.text(url, max: 2048),
47
+ Native.integer(issued_at), Native.text(nonce, max: 256),
48
+ Native.optional_text(access_token), jti.nil? ? nil : Native.text(jti, max: 128),
49
+ capacity: 20_480)
50
+ end
51
+ ensure
52
+ closure # Retain the closure while the native function owns its address.
53
+ end
54
+
55
+ def trusted_now(anchor, observation)
56
+ boot_ids = [anchor, observation].map { |fields| Native.text(fields.fetch(:boot_id)) }
57
+ saved = Native::ANCHOR.malloc(Fiddle::RUBY_FREE)
58
+ %i[server_time wall last_wall monotonic last_effective].each do |field|
59
+ saved.public_send("#{field}=", Native.integer(anchor.fetch(field)))
60
+ end
61
+ saved.boot_id = Fiddle::Pointer[boot_ids[0]]
62
+ observed = Native::OBSERVATION.malloc(Fiddle::RUBY_FREE)
63
+ observed.wall = Native.integer(observation.fetch(:wall))
64
+ observed.monotonic = Native.integer(observation.fetch(:monotonic))
65
+ observed.boot_id = Fiddle::Pointer[boot_ids[1]]
66
+ observed.key_present = Native.boolean(observation.fetch(:key_present))
67
+ @native.scalar(:trusted_now, saved, observed, format: "q")
68
+ ensure
69
+ boot_ids # Keep the pointer-backed strings alive through the call.
70
+ end
71
+
72
+ def receipt_time(issued, nonce_time, previous, sent, received)
73
+ boot_ids = [sent, received].map { |fields| Native.text(fields.fetch(:boot_id)) }
74
+ samples = [sent, received].zip(boot_ids).map do |fields, id|
75
+ sample = Native::MONOTONIC.malloc(Fiddle::RUBY_FREE)
76
+ sample.boot_id = Fiddle::Pointer[id]
77
+ sample.monotonic_ms = Native.integer(fields.fetch(:monotonic_ms))
78
+ sample.confident = Native.boolean(fields.fetch(:confident))
79
+ sample
80
+ end
81
+ @native.scalar(:receipt_time, Native.integer(issued), Native.integer(nonce_time),
82
+ Native.integer(previous), *samples, format: "q")
83
+ ensure
84
+ boot_ids
85
+ end
86
+
87
+ private
88
+
89
+ def verify(kind, keys, arguments)
90
+ raise ArgumentError, "a block is required" unless block_given?
91
+
92
+ with_record(:keyset, [Native.json(keys)]) do |keyset|
93
+ keyset.send(:use) do |handle|
94
+ with_record(kind, [handle, *arguments], creation: :"#{kind}_verify") { |value| yield value }
95
+ end
96
+ end
97
+ end
98
+
99
+ def with_record(kind, arguments, creation: :"#{kind}_new")
100
+ Client.check_callback!
101
+ klass = { keyset: Record, grant: Grant, license_file: LicenseFile, replay_set: ReplaySet }.fetch(kind)
102
+ record = nil
103
+ Thread.handle_interrupt(Exception => :never) do
104
+ record = klass.new(@native, kind, @native.handle(creation, *arguments))
105
+ end
106
+ yield record
107
+ ensure
108
+ record&.send(:close)
109
+ end
110
+
111
+ class Record
112
+ def initialize(native, kind, handle)
113
+ @native, @kind, @handle = native, kind, handle
114
+ @pid = Process.pid
115
+ @mutex = Mutex.new
116
+ end
117
+
118
+ private
119
+
120
+ def initialize_copy(_)
121
+ raise LifecycleError, "PermitPlane handles cannot be copied"
122
+ end
123
+
124
+ def guard!
125
+ raise LifecycleError, "Create a new verifier handle after fork" unless Process.pid == @pid
126
+
127
+ Client.check_callback!
128
+ end
129
+
130
+ def close
131
+ guard!
132
+ @mutex.synchronize do
133
+ Thread.handle_interrupt(Exception => :never) do
134
+ if @handle
135
+ @native.call(:"#{@kind}_free", @handle)
136
+ @handle = nil
137
+ end
138
+ end
139
+ end
140
+ end
141
+
142
+ def use
143
+ guard!
144
+ @mutex.synchronize do
145
+ raise LifecycleError, "Verification block has ended" unless @handle
146
+
147
+ yield @handle
148
+ end
149
+ end
150
+
151
+ def read_claims
152
+ use { |handle| JSON.parse(@native.output(:"#{@kind}_claims_json", handle)) }
153
+ end
154
+ end
155
+
156
+ class Grant < Record
157
+ def claims
158
+ read_claims
159
+ end
160
+
161
+ def info
162
+ use do |handle|
163
+ info = Native::GRANT_INFO.malloc(Fiddle::RUBY_FREE)
164
+ info.struct_size = Native::GRANT_INFO.size
165
+ @native.check(@native.call(:grant_get_info, handle, info))
166
+ { kind: info.kind, issued_at: info.issued_at, expires_at: info.expires_at,
167
+ commercial_deadline: info.commercial_deadline }
168
+ end
169
+ end
170
+
171
+ def has_feature(code, effective_now:)
172
+ use do |handle|
173
+ @native.scalar(:grant_has_feature, handle, Native.text(code),
174
+ Native.integer(effective_now), format: "C") == 1
175
+ end
176
+ end
177
+
178
+ def feature_value(code, effective_now:)
179
+ use { |handle| @native.limit(:grant_limit, handle, Native.text(code), Native.integer(effective_now)) }
180
+ end
181
+
182
+ def lease_kind
183
+ use { |handle| @native.scalar(:grant_lease_kind, handle, format: "l") }
184
+ end
185
+
186
+ def lease_expires
187
+ use { |handle| @native.scalar(:grant_lease_expires, handle, format: "q") }
188
+ end
189
+ end
190
+
191
+ class LicenseFile < Record
192
+ def claims
193
+ read_claims
194
+ end
195
+
196
+ def has_feature(code, effective_now:, time_trusted:)
197
+ use do |handle|
198
+ @native.scalar(:license_file_has_feature, handle, Native.text(code), Native.integer(effective_now),
199
+ Native.boolean(time_trusted), format: "C") == 1
200
+ end
201
+ end
202
+
203
+ def feature_value(code, effective_now:, time_trusted:)
204
+ use do |handle|
205
+ @native.limit(:license_file_limit, handle, Native.text(code), Native.integer(effective_now),
206
+ Native.boolean(time_trusted))
207
+ end
208
+ end
209
+ end
210
+
211
+ class ReplaySet < Record
212
+ def insert(marker)
213
+ use { |handle| @native.check(@native.call(:replay_set_insert, handle, Native.text(marker))) }
214
+ end
215
+
216
+ def verify(token, context)
217
+ use do |handle|
218
+ @native.check(@native.call(:proof_verify, Native.text(token), Native.json(context), handle))
219
+ end
220
+ end
221
+ end
222
+ end
223
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module PermitPlane
4
+ VERSION = "0.1.0.alpha.1"
5
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "permitplane/version"
4
+ require "permitplane/native"
5
+ require "permitplane/host"
6
+ require "permitplane/client"
7
+ require "permitplane/verification"
8
+ require "permitplane/pp_license"
metadata ADDED
@@ -0,0 +1,76 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: permitplane-client
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0.alpha.1
5
+ platform: x64-mingw-ucrt
6
+ authors:
7
+ - Bitbat Oy
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2026-11-26 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: fiddle
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 1.1.1
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '2'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: 1.1.1
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '2'
33
+ description:
34
+ email:
35
+ executables: []
36
+ extensions: []
37
+ extra_rdoc_files: []
38
+ files:
39
+ - LICENSE
40
+ - README.md
41
+ - examples/feature_check.rb
42
+ - lib/permitplane.rb
43
+ - lib/permitplane/THIRD-PARTY-NOTICES.txt
44
+ - lib/permitplane/client.rb
45
+ - lib/permitplane/host.rb
46
+ - lib/permitplane/native.rb
47
+ - lib/permitplane/native/x64-mingw-ucrt/permitplane.dll
48
+ - lib/permitplane/native/x64-mingw-ucrt/provenance.json
49
+ - lib/permitplane/pp_license.rb
50
+ - lib/permitplane/verification.rb
51
+ - lib/permitplane/version.rb
52
+ homepage: https://permitplane.com
53
+ licenses:
54
+ - Apache-2.0
55
+ metadata:
56
+ documentation_uri: https://staging.permitplane.com/docs/quickstart-ruby
57
+ post_install_message:
58
+ rdoc_options: []
59
+ require_paths:
60
+ - lib
61
+ required_ruby_version: !ruby/object:Gem::Requirement
62
+ requirements:
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ version: '3.2'
66
+ required_rubygems_version: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ">"
69
+ - !ruby/object:Gem::Version
70
+ version: 1.3.1
71
+ requirements: []
72
+ rubygems_version: 3.4.19
73
+ signing_key:
74
+ specification_version: 4
75
+ summary: PermitPlane application licensing SDK
76
+ test_files: []