ruby_home-tlv 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/ruby_home/tlv/constants.rb +32 -0
- data/lib/ruby_home/tlv/tlv.rb +28 -0
- data/lib/ruby_home/tlv/utf8_string.rb +9 -0
- data/lib/ruby_home/tlv/version.rb +5 -0
- data/lib/ruby_home/tlv.rb +45 -0
- data/spec/spec_helper.rb +14 -0
- metadata +125 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: aad62338971b49260c5bcdbc07b939efe6ee8c851eecf4a637c9b710d0bfd02b
|
4
|
+
data.tar.gz: 7befc811fe0ca3414448826a5767e17d17484ef9394fdad52b6d90054e007ea6
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: bad405abdbb982dc63d3ac92520a1982c28837aaf4252289890144dfbaf221979738077967e7d31e6e2027b0a9b35234065f89ecaf5adb3049e75bc77a6a31ee
|
7
|
+
data.tar.gz: 5b468cb11932120c7c2c762708107e302894f2fa0732e06f0f2735e95e022c7799eba55f6c30f34870ff59fba6df11fab0053402b847cf93fad286d007cc21bb
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module RubyHome
|
2
|
+
module TLV
|
3
|
+
ERROR_CODES = {
|
4
|
+
unknown: 1,
|
5
|
+
authentication: 2,
|
6
|
+
backoff: 3,
|
7
|
+
max_peers: 4,
|
8
|
+
max_tries: 5,
|
9
|
+
unavailable: 6,
|
10
|
+
busy: 7,
|
11
|
+
}.freeze
|
12
|
+
|
13
|
+
NAME_TYPES = {
|
14
|
+
method: 0,
|
15
|
+
identifier: 1,
|
16
|
+
salt: 2,
|
17
|
+
public_key: 3,
|
18
|
+
proof: 4,
|
19
|
+
encrypted_data: 5,
|
20
|
+
state: 6,
|
21
|
+
error: 7,
|
22
|
+
retry_delay: 8,
|
23
|
+
certificate: 9,
|
24
|
+
signature: 10,
|
25
|
+
permissions: 11,
|
26
|
+
fragment_data: 12,
|
27
|
+
fragment_last: 13,
|
28
|
+
}.freeze
|
29
|
+
|
30
|
+
TYPE_NAMES = NAME_TYPES.invert.freeze
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'ruby_home/tlv/utf8_string'
|
2
|
+
|
3
|
+
module RubyHome
|
4
|
+
module TLV
|
5
|
+
class TLV < BinData::Record
|
6
|
+
uint8 :type_id
|
7
|
+
uint8 :len, value: -> { val.to_binary_s.length }
|
8
|
+
choice :val, selection: :type_id do
|
9
|
+
string :default, read_length: :len
|
10
|
+
|
11
|
+
uint8 0, read_length: :len
|
12
|
+
utf8_string 1, read_length: :len
|
13
|
+
string 2, read_length: :len
|
14
|
+
string 3, read_length: :len
|
15
|
+
string 4, read_length: :len
|
16
|
+
string 5, read_length: :len
|
17
|
+
uint8 6, read_length: :len
|
18
|
+
uint8 7, read_length: :len
|
19
|
+
uint8 8, read_length: :len
|
20
|
+
string 9, read_length: :len
|
21
|
+
string 10, read_length: :len
|
22
|
+
uint8 11, read_length: :len
|
23
|
+
string 12, read_length: :len
|
24
|
+
string 13, read_length: :len
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'bindata'
|
2
|
+
require 'ruby_home/tlv/constants'
|
3
|
+
require 'ruby_home/tlv/tlv'
|
4
|
+
require 'ruby_home/tlv/version'
|
5
|
+
|
6
|
+
module RubyHome
|
7
|
+
module TLV
|
8
|
+
READER = BinData::Array.new(type: :tlv, read_until: :eof)
|
9
|
+
|
10
|
+
class << self
|
11
|
+
def decode(string)
|
12
|
+
READER.clear
|
13
|
+
READER.read(string)
|
14
|
+
READER.snapshot.each_with_object({}) do |(hash), memo|
|
15
|
+
type = TYPE_NAMES[hash[:type_id]]
|
16
|
+
next unless type
|
17
|
+
|
18
|
+
if memo[type]
|
19
|
+
memo[type] << hash[:val]
|
20
|
+
else
|
21
|
+
memo[type] = hash[:val]
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def encode(hash)
|
27
|
+
hash.each_with_object(String.new) do |(key, value), memo|
|
28
|
+
type_id = NAME_TYPES[key]
|
29
|
+
next unless type_id
|
30
|
+
|
31
|
+
fragments = if value.is_a?(String)
|
32
|
+
value.scan(/.{1,255}/m)
|
33
|
+
else
|
34
|
+
[value]
|
35
|
+
end
|
36
|
+
|
37
|
+
fragments.each do |frame_value|
|
38
|
+
tlv = TLV.new(type_id: type_id, val: frame_value)
|
39
|
+
memo << tlv.to_binary_s
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require "bundler/setup"
|
2
|
+
require "ruby_home/tlv"
|
3
|
+
|
4
|
+
RSpec.configure do |config|
|
5
|
+
# Enable flags like --only-failures and --next-failure
|
6
|
+
config.example_status_persistence_file_path = ".rspec_status"
|
7
|
+
|
8
|
+
# Disable RSpec exposing methods globally on `Module` and `main`
|
9
|
+
config.disable_monkey_patching!
|
10
|
+
|
11
|
+
config.expect_with :rspec do |c|
|
12
|
+
c.syntax = :expect
|
13
|
+
end
|
14
|
+
end
|
metadata
ADDED
@@ -0,0 +1,125 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ruby_home-tlv
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Karl Entwistle
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-02-28 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bindata
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.4'
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 2.4.3
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - "~>"
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '2.4'
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 2.4.3
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: bundler
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - "~>"
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '1.17'
|
40
|
+
type: :development
|
41
|
+
prerelease: false
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - "~>"
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '1.17'
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: rake
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - "~>"
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '10.0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - "~>"
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '10.0'
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: rspec
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - "~>"
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '3.0'
|
68
|
+
type: :development
|
69
|
+
prerelease: false
|
70
|
+
version_requirements: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - "~>"
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '3.0'
|
75
|
+
- !ruby/object:Gem::Dependency
|
76
|
+
name: byebug
|
77
|
+
requirement: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - "~>"
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '11.0'
|
82
|
+
type: :development
|
83
|
+
prerelease: false
|
84
|
+
version_requirements: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - "~>"
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '11.0'
|
89
|
+
description: encode / decode TRV HAP
|
90
|
+
email:
|
91
|
+
- karl@entwistle.com
|
92
|
+
executables: []
|
93
|
+
extensions: []
|
94
|
+
extra_rdoc_files: []
|
95
|
+
files:
|
96
|
+
- lib/ruby_home/tlv.rb
|
97
|
+
- lib/ruby_home/tlv/constants.rb
|
98
|
+
- lib/ruby_home/tlv/tlv.rb
|
99
|
+
- lib/ruby_home/tlv/utf8_string.rb
|
100
|
+
- lib/ruby_home/tlv/version.rb
|
101
|
+
- spec/spec_helper.rb
|
102
|
+
homepage: https://github.com/karlentwistle/ruby_home-tlv
|
103
|
+
licenses: []
|
104
|
+
metadata: {}
|
105
|
+
post_install_message:
|
106
|
+
rdoc_options: []
|
107
|
+
require_paths:
|
108
|
+
- lib
|
109
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
110
|
+
requirements:
|
111
|
+
- - ">="
|
112
|
+
- !ruby/object:Gem::Version
|
113
|
+
version: '0'
|
114
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
115
|
+
requirements:
|
116
|
+
- - ">="
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
version: '0'
|
119
|
+
requirements: []
|
120
|
+
rubygems_version: 3.0.1
|
121
|
+
signing_key:
|
122
|
+
specification_version: 4
|
123
|
+
summary: encode / decode TRV HAP
|
124
|
+
test_files:
|
125
|
+
- spec/spec_helper.rb
|