ldap-ber 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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: d62933a4b34660baba5b9ece1311ec054c8fc68e1384e845bc7d99bc3199b61c
4
+ data.tar.gz: e9c58a69cbd8a77abd5e9d2532a618a797c5a6caa2c75948299f76ac7f93e4fa
5
+ SHA512:
6
+ metadata.gz: d83da22ad3a51c98800f5e6ca9c7f8e10a4a25b8dbbb96f35c7c99ca2024cdc516d9954503a4c1e0b32c8da67dc8df4a475a140ec62f478465650745bf059cb8
7
+ data.tar.gz: 1e2f827f2952026dfc2b608bf4c5e2a607c2e70b2a70eb40aa6158a2a5cd7db64b98d3e03f668e77eaadd924823ca263d9a1c7ebf97d70f3cd06cd9358e69a0a
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ *.a
2
+ *.bundle
3
+ *.gem
4
+ *.html
5
+ *.o
6
+ *.so
7
+ .ruby-version
8
+ .bundle/
9
+ .yardoc
10
+ coverage/
11
+ doc/
12
+ Gemfile.lock
13
+ pkg
14
+ tags
data/.rspec ADDED
@@ -0,0 +1,6 @@
1
+ --require spec_helper
2
+ --order random
3
+ --format documentation
4
+ --color
5
+ --profile
6
+ --fail-fast
data/.rubocop.yml ADDED
@@ -0,0 +1,20 @@
1
+ inherit_from: .rubocop_todo.yml
2
+ require: rubocop-performance
3
+
4
+ AllCops:
5
+ Include:
6
+ - Rakefile
7
+ - lib/ber/**/*.rb
8
+ Exclude:
9
+ - '**/.*'
10
+ - doc/**/*
11
+ - spec/**/*
12
+ TargetRubyVersion: 2.4
13
+
14
+
15
+ Style/HashEachMethods:
16
+ Enabled: true
17
+ Style/HashTransformKeys:
18
+ Enabled: true
19
+ Style/HashTransformValues:
20
+ Enabled: true
data/.rubocop_todo.yml ADDED
@@ -0,0 +1,44 @@
1
+ # This configuration was generated by
2
+ # `rubocop --auto-gen-config`
3
+ # on 2021-02-15 16:05:18 +0000 using RuboCop version 0.80.1.
4
+ # The point is for the user to remove these configuration records
5
+ # one by one as the offenses are removed from the code base.
6
+ # Note that changes in the inspected code, or installation of new
7
+ # versions of RuboCop, may require this file to be generated again.
8
+
9
+ # Offense count: 1
10
+ # Configuration parameters: AllowComments.
11
+ Lint/SuppressedException:
12
+ Exclude:
13
+ - 'Rakefile'
14
+
15
+ # Offense count: 2
16
+ Metrics/AbcSize:
17
+ Max: 39
18
+
19
+ # Offense count: 2
20
+ Metrics/CyclomaticComplexity:
21
+ Max: 16
22
+
23
+ # Offense count: 2
24
+ # Configuration parameters: CountComments, ExcludedMethods.
25
+ Metrics/MethodLength:
26
+ Max: 47
27
+
28
+ # Offense count: 2
29
+ Metrics/PerceivedComplexity:
30
+ Max: 14
31
+
32
+ # Offense count: 4
33
+ Style/Documentation:
34
+ Exclude:
35
+ - 'lib/ber/identified/null.rb'
36
+ - 'lib/ber/identified/oid.rb'
37
+
38
+
39
+ # Offense count: 4
40
+ # Cop supports --auto-correct.
41
+ # Configuration parameters: AutoCorrect, AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
42
+ # URISchemes: http, https
43
+ Layout/LineLength:
44
+ Max: 104
data/Gemfile ADDED
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ gemspec
6
+
7
+ group :development do
8
+ gem 'rubocop', require: false
9
+ gem 'rubocop-performance', require: false
10
+ end
11
+
12
+ group :test do
13
+ gem 'pry', platforms: %i[jruby rbx]
14
+ gem 'pry-byebug', platforms: :mri
15
+ gem 'rspec', require: false
16
+ gem 'simplecov', require: false
17
+ end
data/LICENSE ADDED
@@ -0,0 +1,25 @@
1
+ Copyright (c) 2017-2021 Peter Hamilton
2
+
3
+ Copyright 2006–2011 by Francis Cianfrocca and other contributors.
4
+
5
+
6
+ MIT License
7
+
8
+ Permission is hereby granted, free of charge, to any person obtaining
9
+ a copy of this software and associated documentation files (the
10
+ "Software"), to deal in the Software without restriction, including
11
+ without limitation the rights to use, copy, modify, merge, publish,
12
+ distribute, sublicense, and/or sell copies of the Software, and to
13
+ permit persons to whom the Software is furnished to do so, subject to
14
+ the following conditions:
15
+
16
+ The above copyright notice and this permission notice shall be
17
+ included in all copies or substantial portions of the Software.
18
+
19
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
20
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
22
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
23
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
24
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
25
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,9 @@
1
+ # Basic Encoding Rules for LDAP
2
+
3
+ The Basic Encoding Rules ([BER](https://ldapwiki.com/wiki/Basic%20Encoding%20Rules)) are a set of [Abstract Syntax Notation One](https://ldapwiki.com/wiki/Abstract%20Syntax%20Notation%20One)
4
+ encoding rules that define a specific way in which information may be encoded in a binary form.
5
+
6
+ This gem contains the _BER_ core extensions from [ruby-net-ldap](https://github.com/ruby-ldap/ruby-net-ldap/tree/master/lib/net/ber/core_ext)
7
+ refactored into refinements for use in the [rom-ldap](https://gitlab.com/peterdavidhamilton/rom-ldap) gem and the accompanying TestUnit tests have been rewritten in Rspec.
8
+
9
+ I would like to thank the authors of `NET::LDAP` for their continued work.
data/Rakefile ADDED
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ if ENV['PRY']
4
+ begin
5
+ require 'pry-byebug'
6
+ rescue LoadError
7
+ end
8
+ end
9
+
10
+ require 'bundler/gem_tasks'
11
+
12
+ require 'rspec/core/rake_task'
13
+
14
+ RSpec::Core::RakeTask.new(:spec)
15
+
16
+ task default: %i[spec]
data/bin/console ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'bundler/setup'
5
+ require 'ber'
6
+ require 'pry'
7
+
8
+ Pry.start
data/bin/setup ADDED
@@ -0,0 +1,5 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
data/ldap-ber.gemspec ADDED
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('lib', __dir__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+
6
+ require 'ber/version'
7
+
8
+ Gem::Specification.new do |spec|
9
+ spec.name = 'ldap-ber'
10
+ spec.version = BER::VERSION.dup
11
+ spec.authors = ['Peter Hamilton']
12
+ spec.email = ['pete@peterdavidhamilton.com']
13
+ spec.summary = 'LDAP Basic Encoding Rules: used by rom-ldap'
14
+ spec.description = 'Refactored from Net:LDAP gem.'
15
+ spec.homepage = 'https://gitlab.com/peterdavidhamilton/ldap-ber'
16
+ spec.license = 'MIT'
17
+ spec.files = `git ls-files -z`.split("\x0")
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.metadata['yard.run'] = 'yri'
22
+ spec.required_ruby_version = '>= 2.4.0'
23
+
24
+ spec.add_runtime_dependency 'dry-core', '~> 0.4'
25
+ spec.add_runtime_dependency 'dry-initializer', '~> 3.0'
26
+
27
+ spec.add_development_dependency 'bundler', '~> 2.0'
28
+ spec.add_development_dependency 'rake', '~> 13.0'
29
+ spec.add_development_dependency 'rspec', '~> 3.9'
30
+ end
data/lib/ber.rb ADDED
@@ -0,0 +1,76 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'dry/core/constants'
4
+ require 'yaml'
5
+ require 'pathname'
6
+ require 'ber/version'
7
+ require 'ber/function'
8
+ require 'ber/refinements'
9
+
10
+ # Basic Encoding Rules
11
+ #
12
+ module BER
13
+ include Dry::Core::Constants
14
+
15
+ def self.function
16
+ @function ||= Function.new
17
+ end
18
+
19
+ # Path to gem root
20
+ #
21
+ # @return [Pathname]
22
+ #
23
+ # @api private
24
+ def self.root
25
+ Pathname(File.dirname(__FILE__))
26
+ end
27
+
28
+ #
29
+ #
30
+ # @return [Hash]
31
+ #
32
+ # @api private
33
+ def self.config
34
+ @config ||= YAML.load_file(root.join('ber.yaml')).freeze
35
+ end
36
+
37
+ #
38
+ #
39
+ # @param type [Symbol] (:response)
40
+ #
41
+ # @param val [Integer, Symbol]
42
+ #
43
+ # @return [Symbol, Integer]
44
+ #
45
+ # @api private
46
+ def self.fetch(type, val)
47
+ case val
48
+ when Integer then config[type][val]
49
+ when Symbol then config[type].key(val)
50
+ end
51
+ end
52
+
53
+ def self.compile_syntax(syntax)
54
+ out = [nil] * 256
55
+
56
+ syntax.each do |tag_class_id, encodings|
57
+ tag_class = config[:tag_class][tag_class_id]
58
+ encodings.each do |encoding_id, classes|
59
+ encoding = config[:encoding_type][encoding_id]
60
+ object_class = tag_class + encoding
61
+ classes.each do |number, object_type|
62
+ out[object_class + number] = object_type
63
+ end
64
+ end
65
+ end
66
+
67
+ out
68
+ end
69
+
70
+ Error = Class.new(RuntimeError)
71
+
72
+ ASN_SYNTAX = compile_syntax(config[:syntax]).freeze
73
+ IDENTIFIED = compile_syntax(config[:identified_type]).freeze
74
+ MAX_FIXNUM_SIZE = 0.size
75
+ WILDCARD = '*'
76
+ end
data/lib/ber.yaml ADDED
@@ -0,0 +1,199 @@
1
+ ---
2
+ :tag_class:
3
+ :universal: 0b00000000 # 0
4
+ :application: 0b01000000 # 64
5
+ :context_specific: 0b10000000 # 128
6
+ :private: 0b11000000 # 192
7
+
8
+ :encoding_type:
9
+ :primitive: 0b00000000 # 0
10
+ :constructed: 0b00100000 # 32
11
+
12
+ :identified_type:
13
+ :universal:
14
+ :primitive:
15
+ 1: :boolean
16
+ 2: :integer
17
+ 4: :string
18
+ 5: :null
19
+ 6: :oid
20
+ 10: :integer
21
+ 13: :string # (relative OID)
22
+
23
+ :constructed:
24
+ 16: :array
25
+ 17: :array
26
+
27
+ :context_specific:
28
+ :primitive:
29
+ 10: :integer
30
+
31
+ #
32
+ # Abstract Syntax Notation One - ASN.1
33
+ #
34
+ :syntax:
35
+ :application:
36
+ :primitive:
37
+ 2: # UnbindRequest body # nil!
38
+ :constructed:
39
+ 0: :array # BindRequest
40
+ 1: :array # BindResponse
41
+ 2: :array # UnbindRequest
42
+ 3: :array # SearchRequest
43
+ 4: :array # SearchData
44
+ 5: :array # SearchResult
45
+ 6: :array # ModifyRequest
46
+ 7: :array # ModifyResponse
47
+ 8: :array # AddRequest
48
+ 9: :array # AddResponse
49
+ 10: :array # DelRequest
50
+ 11: :array # DelResponse
51
+ 12: :array # ModifyRdnRequest
52
+ 13: :array # ModifyRdnResponse
53
+ 14: :array # CompareRequest
54
+ 15: :array # CompareResponse
55
+ 16: :array # AbandonRequest
56
+ 19: :array # SearchResultReferral
57
+ 24: :array # Unsolicited Notification
58
+
59
+ :universal:
60
+ :constructed:
61
+ 107: :array # ExtendedResponse (PasswdModifyResponseValue)
62
+
63
+ :context_specific:
64
+ :primitive:
65
+ 0: :string # password
66
+ 1: :string # Kerberos v4
67
+ 2: :string # Kerberos v5
68
+ 3: :string # SearchFilter-extensible
69
+ 4: :string # SearchFilter-extensible
70
+ 7: :string # serverSaslCreds
71
+ :constructed:
72
+ 0: :array # RFC-2251 Control and Filter-AND
73
+ 1: :array # SearchFilter-OR
74
+ 2: :array # SearchFilter-NOT
75
+ 3: :array # Search referral
76
+ 4: :array # unknown use in Microsoft Outlook
77
+ 5: :array # SearchFilter-GE
78
+ 6: :array # SearchFilter-LE
79
+ 7: :array # serverSaslCreds
80
+ 9: :array # SearchFilter-extensible
81
+
82
+
83
+ :request:
84
+ :con_and: 0xa0 # constructed 0, "and"
85
+ :con_or: 0xa1 # constructed 1, "or"
86
+ :con_not: 0xa2 # constructed 2, "not"
87
+ :equality_match: 0xa3 # constructed 3, "equalityMatch"
88
+ :substring: 0xa4 # constructed 4, "substring"
89
+ :op_gte: 0xa5 # constructed 5, "greaterOrEqual"
90
+ :op_lte: 0xa6 # constructed 6, "lessOrEqual"
91
+ :substr_initial: 0x80 # primitive 0, SubstringFilter "initial"
92
+ :substr_any: 0x81 # primitive 0, SubstringFilter "any"
93
+ :substr_final: 0x82 # primitive 0, SubstringFilter "final"
94
+ :is_present: 0x87 # primitive 7, "present"
95
+ :op_ext: 0xa9 # constructed 9, "extensible comparison"
96
+
97
+
98
+ :response:
99
+ 0: :bind_request
100
+ 1: :bind_result
101
+ 2: :unbind_request
102
+ 3: :search_request
103
+ 4: :search_returned_data
104
+ 5: :search_result
105
+ 6: :modify_request
106
+ 7: :modify_response
107
+ 8: :add_request
108
+ 9: :add_response
109
+ 10: :delete_request
110
+ 11: :delete_response
111
+ 12: :modify_rdn_request
112
+ 13: :modify_rdn_response
113
+ 14: :compare_request
114
+ 15: :compare_response
115
+ 16: :abandon_request
116
+ 17: :unknown
117
+ 18: :unknown
118
+ 19: :search_result_referral
119
+ 20: :unknown
120
+ 21: :unknown
121
+ 22: :unknown
122
+ 23: :extended_request
123
+ 24: :extended_response
124
+ 25: :intermediate_response
125
+
126
+ :result:
127
+ 0: :success
128
+ 1: :operations_error
129
+ 2: :protocol_error
130
+ 3: :time_limit_exceeded
131
+ 4: :size_limit_exceeded
132
+ 5: :compare_false
133
+ 6: :compare_true
134
+ 7: :auth_method_not_supported
135
+ 8: :stronger_auth_required
136
+ 9: :reserved
137
+ 10: :referral
138
+ 11: :admin_limit_exceeded
139
+ 12: :unavailable_critical_extension
140
+ 13: :confidentiality_required
141
+ 14: :sasl_bind_in_progress
142
+ 15: :not_used
143
+ 16: :no_such_attribute
144
+ 17: :undefined_attribute_type
145
+ 18: :inappropriate_matching
146
+ 19: :constraint_violation
147
+ 20: :attribute_or_value_exists
148
+ 21: :invalid_attribute_syntax
149
+ #
150
+ # 22..31 - Not used.
151
+ #
152
+ 32: :no_such_object
153
+ 33: :alias_problem
154
+ 34: :invalid_dn_syntax
155
+ 35: :ldap_is_leaf
156
+ 36: :alias_dereferencing_problem
157
+ #
158
+ # 37..47 - Not used.
159
+ #
160
+ 48: :inappropriate_authentication
161
+ 49: :invalid_credentials
162
+ 50: :insufficient_access_rights
163
+ 51: :busy
164
+ 52: :unavailable
165
+ 53: :unwilling_to_perform
166
+ 54: :loop_detected
167
+ #
168
+ # 55..63 - Not used.
169
+ #
170
+ 64: :naming_violation
171
+ 65: :object_class_violation
172
+ 66: :not_allowed_on_non_leaf
173
+ 67: :not_allowed_on_rdn
174
+ 68: :entry_already_exists
175
+ 69: :object_class_mods_prohibited
176
+ 70: :reserved_for_cldap
177
+ 71: :affects_multiple_dsas
178
+ #
179
+ # 72..79 - Not used.
180
+ #
181
+ 80: :other
182
+ 81: :server_down
183
+ 82: :local_error
184
+ 83: :encoding_error
185
+ 84: :decoding_error
186
+ 85: :timeout
187
+ 86: :auth_method_unknown
188
+ 87: :filter_error
189
+ 88: :user_cancelled
190
+ 89: :param_error
191
+ 90: :no_memory
192
+ 91: :connect_error
193
+ 92: :not_supported
194
+ 93: :control_not_found
195
+ 94: :no_results_returned
196
+ 95: :more_results
197
+ 96: :client_loop
198
+ 97: :referral_limit
199
+