kobako 0.29.0-aarch64-linux → 0.31.0-aarch64-linux

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 (108) hide show
  1. checksums.yaml +4 -4
  2. data/.release-please-manifest.json +1 -1
  3. data/CHANGELOG.md +552 -10
  4. data/README.md +126 -564
  5. data/ROADMAP.md +3 -2
  6. data/crates/kobako-runtime/CHANGELOG.md +488 -1
  7. data/crates/kobako-runtime/README.md +11 -4
  8. data/crates/kobako-transport/CHANGELOG.md +39 -2
  9. data/crates/kobako-transport/README.md +8 -8
  10. data/crates/kobako-wasmtime/CHANGELOG.md +315 -8
  11. data/crates/kobako-wasmtime/README.md +11 -6
  12. data/crates/kobako-wasmtime/src/preview1/testsuite-expected.txt +6 -0
  13. data/crates/kobako-wasmtime/wit/deps/cli.wit +233 -0
  14. data/crates/kobako-wasmtime/wit/deps/clocks.wit +162 -0
  15. data/crates/kobako-wasmtime/wit/deps/filesystem.wit +589 -0
  16. data/crates/kobako-wasmtime/wit/deps/http.wit +733 -0
  17. data/crates/kobako-wasmtime/wit/deps/io.wit +299 -0
  18. data/crates/kobako-wasmtime/wit/deps/random.wit +92 -0
  19. data/crates/kobako-wasmtime/wit/deps/sockets.wit +949 -0
  20. data/crates/kobako-wasmtime/witx/typenames.witx +750 -0
  21. data/crates/kobako-wasmtime/witx/wasi_snapshot_preview1.witx +441 -0
  22. data/data/kobako.wasm +0 -0
  23. data/lib/kobako/3.3/kobako.so +0 -0
  24. data/lib/kobako/3.4/kobako.so +0 -0
  25. data/lib/kobako/4.0/kobako.so +0 -0
  26. data/lib/kobako/catalog/extensions.rb +19 -7
  27. data/lib/kobako/catalog/flags.rb +4 -6
  28. data/lib/kobako/catalog/grants.rb +5 -4
  29. data/lib/kobako/catalog/handles.rb +9 -31
  30. data/lib/kobako/catalog/mount.rb +12 -12
  31. data/lib/kobako/catalog/network.rb +35 -0
  32. data/lib/kobako/catalog/replacements.rb +28 -0
  33. data/lib/kobako/catalog/services.rb +7 -21
  34. data/lib/kobako/catalog/snippets.rb +10 -25
  35. data/lib/kobako/catalog.rb +4 -1
  36. data/lib/kobako/codec/{utils.rb → boundary.rb} +5 -3
  37. data/lib/kobako/codec/decoder.rb +12 -12
  38. data/lib/kobako/codec/ext_types.rb +5 -7
  39. data/lib/kobako/codec/handle_walk.rb +5 -47
  40. data/lib/kobako/codec/nesting.rb +7 -7
  41. data/lib/kobako/codec/value_budget.rb +134 -42
  42. data/lib/kobako/codec.rb +1 -1
  43. data/lib/kobako/context.rb +28 -15
  44. data/lib/kobako/errors.rb +15 -12
  45. data/lib/kobako/extension.rb +3 -2
  46. data/lib/kobako/filesystem.rb +53 -15
  47. data/lib/kobako/handle.rb +2 -2
  48. data/lib/kobako/names.rb +28 -0
  49. data/lib/kobako/network.rb +210 -0
  50. data/lib/kobako/outcome.rb +7 -7
  51. data/lib/kobako/payload/arguments.rb +2 -2
  52. data/lib/kobako/pool.rb +47 -25
  53. data/lib/kobako/runtime.rb +3 -2
  54. data/lib/kobako/sandbox.rb +113 -56
  55. data/lib/kobako/sandbox_options.rb +41 -107
  56. data/lib/kobako/snippet/bytecode.rb +1 -1
  57. data/lib/kobako/snippet/source.rb +1 -1
  58. data/lib/kobako/transport/argument_wrap.rb +64 -0
  59. data/lib/kobako/transport/block_failure.rb +1 -1
  60. data/lib/kobako/transport/dispatcher.rb +10 -10
  61. data/lib/kobako/transport/exposure.rb +28 -17
  62. data/lib/kobako/transport/reflection.rb +28 -11
  63. data/lib/kobako/transport/run.rb +13 -28
  64. data/lib/kobako/transport/yielder.rb +3 -10
  65. data/lib/kobako/transport.rb +1 -0
  66. data/lib/kobako/version.rb +1 -1
  67. data/lib/kobako.rb +38 -0
  68. data/release-please-config.json +16 -0
  69. data/sig/core/thread.rbs +6 -0
  70. data/sig/kobako/catalog/extensions.rbs +5 -3
  71. data/sig/kobako/catalog/grants.rbs +7 -4
  72. data/sig/kobako/catalog/handles.rbs +2 -4
  73. data/sig/kobako/catalog/mount.rbs +3 -5
  74. data/sig/kobako/catalog/network.rbs +20 -0
  75. data/sig/kobako/catalog/replacements.rbs +14 -0
  76. data/sig/kobako/catalog/services.rbs +1 -5
  77. data/sig/kobako/catalog/snippets.rbs +3 -5
  78. data/sig/kobako/catalog.rbs +1 -1
  79. data/sig/kobako/codec/boundary.rbs +9 -0
  80. data/sig/kobako/codec/decoder.rbs +1 -1
  81. data/sig/kobako/codec/handle_walk.rbs +0 -6
  82. data/sig/kobako/codec/nesting.rbs +2 -2
  83. data/sig/kobako/codec/value_budget.rbs +48 -5
  84. data/sig/kobako/codec.rbs +1 -2
  85. data/sig/kobako/context.rbs +4 -2
  86. data/sig/kobako/errors.rbs +4 -4
  87. data/sig/kobako/filesystem.rbs +38 -15
  88. data/sig/kobako/guest_yielder.rbs +1 -1
  89. data/sig/kobako/network.rbs +115 -0
  90. data/sig/kobako/outcome.rbs +1 -1
  91. data/sig/kobako/payload/arguments.rbs +1 -1
  92. data/sig/kobako/pool.rbs +8 -4
  93. data/sig/kobako/runtime.rbs +32 -3
  94. data/sig/kobako/sandbox.rbs +22 -7
  95. data/sig/kobako/sandbox_options.rbs +29 -38
  96. data/sig/kobako/transport/argument_wrap.rbs +15 -0
  97. data/sig/kobako/transport/dispatcher.rbs +2 -2
  98. data/sig/kobako/transport/error.rbs +1 -1
  99. data/sig/kobako/transport/exposure.rbs +3 -5
  100. data/sig/kobako/transport/reflection.rbs +12 -2
  101. data/sig/kobako/transport/run.rbs +3 -5
  102. data/sig/kobako/transport/yielder.rbs +0 -3
  103. data/sig/kobako/transport.rbs +2 -2
  104. data/sig/kobako.rbs +13 -0
  105. metadata +26 -8
  106. data/lib/kobako/constant_name.rb +0 -8
  107. data/sig/kobako/codec/utils.rbs +0 -9
  108. data/sig/kobako/constant_name.rbs +0 -3
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Kobako
4
+ module Catalog
5
+ class Network < Data.define(:name, :entry) # :nodoc:
6
+ # The entry named +name+: +entry+ as it stands, or a Builder adding what
7
+ # the block declares to it. Raises TypeError for a name of another class,
8
+ # and ArgumentError for an empty name, which no Context could replace it
9
+ # by.
10
+ def initialize(name:, entry:)
11
+ name = Kobako.to_name(name, "network name").freeze
12
+ Kobako::Network.validate_name(name)
13
+
14
+ if block_given?
15
+ entry = Kobako::Network::Builder.new(entry)
16
+ yield entry
17
+ end
18
+ super
19
+ end
20
+
21
+ # The kind and name a Context replaces this entry by, so a Grant of
22
+ # another kind never meets it.
23
+ def key = [:network, name]
24
+
25
+ # Why +other+ cannot be given beside this entry, or +nil+: a name means
26
+ # one entry, as a path means one Mount.
27
+ def conflict(other)
28
+ "network entry #{name.inspect} is already given" if other.key == key
29
+ end
30
+
31
+ # The entry as the native side reads it.
32
+ def to_native = [name, entry]
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Kobako
4
+ module Catalog
5
+ # The Grants one invocation's Context replaced, each standing in for the
6
+ # Sandbox's Grant at its key.
7
+ class Replacements # :nodoc:
8
+ def initialize(grants)
9
+ @grants = grants
10
+ @replaced = {} # : Hash[Grants::key, Grants::grant]
11
+ end
12
+
13
+ # Have +grant+ stand in for the Grant at its key, raising ArgumentError
14
+ # with +refusal+ when the Sandbox holds none there, so a replacement
15
+ # never adds a Grant.
16
+ def replace(grant, refusal)
17
+ raise ArgumentError, refusal unless @grants.include?(grant)
18
+
19
+ @replaced[grant.key] = grant
20
+ nil
21
+ end
22
+
23
+ # The Sandbox's Grants with each replacement in place, as Grants#entries
24
+ # gives them.
25
+ def entries = @grants.entries(@replaced)
26
+ end
27
+ end
28
+ end
@@ -1,25 +1,20 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative "../constant_name"
4
3
  require_relative "../errors"
5
4
  require_relative "../transport/exposure"
6
5
 
7
6
  module Kobako
8
7
  module Catalog
9
8
  class Services # :nodoc:
10
- # The Guest Binary keeps this namespace for constants it may add later.
11
- RESERVED_NAMESPACE = "Kobako"
12
-
13
9
  def initialize
14
10
  @bindings = {} # : Hash[String, Kobako::Transport::Exposure]
15
11
  end
16
12
 
17
13
  # The binding records +object+'s Exposure as it stands now.
18
14
  def bind(path, object)
19
- path_str = validate_path!(path)
20
- if reserved?(path_str)
21
- raise ArgumentError,
22
- "Service path #{path_str} is in the reserved #{RESERVED_NAMESPACE} namespace"
15
+ path_str = validate_path(path)
16
+ if Kobako.reserved_path?(path_str)
17
+ raise ArgumentError, "Service path #{path_str} is in the reserved Kobako namespace"
23
18
  end
24
19
  raise ArgumentError, "Service path #{path_str} conflicts with an existing binding" if collision?(path_str)
25
20
 
@@ -46,26 +41,17 @@ module Kobako
46
41
 
47
42
  private
48
43
 
49
- def validate_path!(path)
50
- path_str = path.to_s
51
- segments = path_str.split("::", -1)
52
- return path_str if !segments.empty? && segments.all? { |seg| CONSTANT_NAME.match?(seg) }
44
+ def validate_path(path)
45
+ path_str = Kobako.to_name(path, "bind path")
46
+ return path_str if Kobako.constant_path?(path_str)
53
47
 
54
48
  raise ArgumentError,
55
49
  "bind path must be constant-form segments joined by '::' (got #{path.inspect})"
56
50
  end
57
51
 
58
- def reserved?(path)
59
- path.split("::").first == RESERVED_NAMESPACE
60
- end
61
-
62
52
  # Keeps a name from being both a bound Service and a grouping prefix.
63
53
  def collision?(path)
64
- @bindings.each_key.any? do |existing|
65
- existing == path ||
66
- existing.start_with?("#{path}::") ||
67
- path.start_with?("#{existing}::")
68
- end
54
+ @bindings.each_key.any? { |bound| Kobako.paths_collide?(path, bound) }
69
55
  end
70
56
  end
71
57
  end
@@ -1,6 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative "../constant_name"
4
3
  require_relative "../snippet"
5
4
 
6
5
  module Kobako
@@ -40,19 +39,19 @@ module Kobako
40
39
  if binary
41
40
  raise ArgumentError, "cannot combine binary: with code: / name:" if code || name
42
41
 
43
- register_binary!(binary)
42
+ register_binary(binary)
44
43
  else
45
- register_source!(code, name)
44
+ register_source(code, name)
46
45
  end
47
46
  end
48
47
 
49
48
  private
50
49
 
51
- def register_source!(code, name)
52
- code, name = ensure_source_args!(code, name)
53
- body = Catalog.to_utf8!(code, "code")
50
+ def register_source(code, name)
51
+ code, name = ensure_source_args(code, name)
52
+ body = Catalog.to_utf8(code, "code")
54
53
 
55
- name_sym = normalize_name(name)
54
+ name_sym = Kobako.to_constant_name(name, "snippet name")
56
55
  if @entries.any? { |e| e.is_a?(Snippet::Source) && e.name == name_sym }
57
56
  raise ArgumentError, "snippet #{name_sym.inspect} already preloaded"
58
57
  end
@@ -63,9 +62,9 @@ module Kobako
63
62
 
64
63
  # The +code:+ type check runs first so an explicit +code: nil+ reads
65
64
  # as a type error rather than a missing keyword.
66
- def ensure_source_args!(code, name)
65
+ def ensure_source_args(code, name)
67
66
  raise ArgumentError, "missing keyword: code: + name:, or binary:" if code.nil? && name.nil?
68
- raise ArgumentError, "code must be a String, got #{code.class}" unless code.is_a?(String)
67
+ raise TypeError, "code must be a String, got #{code.class}" unless code.is_a?(String)
69
68
  raise ArgumentError, "missing keyword: name:" if name.nil?
70
69
 
71
70
  [code, name]
@@ -73,8 +72,8 @@ module Kobako
73
72
 
74
73
  # Kept as bytes whatever encoding the caller tagged them with, since
75
74
  # the guest reads them as bytecode rather than text.
76
- def register_binary!(bytes)
77
- raise ArgumentError, "binary must be a String, got #{bytes.class}" unless bytes.is_a?(String)
75
+ def register_binary(bytes)
76
+ raise TypeError, "binary must be a String, got #{bytes.class}" unless bytes.is_a?(String)
78
77
 
79
78
  @entries << Snippet::Bytecode.new(body: bytes.dup.force_encoding(Encoding::ASCII_8BIT))
80
79
  nil
@@ -91,20 +90,6 @@ module Kobako
91
90
  [Snippet::Bytecode::KIND, nil, entry.body]
92
91
  end
93
92
  end
94
-
95
- def normalize_name(name)
96
- unless name.is_a?(Symbol) || name.is_a?(String)
97
- raise ArgumentError, "snippet name must be a Symbol or String, got #{name.class}"
98
- end
99
-
100
- name_str = name.to_s
101
- unless CONSTANT_NAME.match?(name_str)
102
- raise ArgumentError,
103
- "snippet name must match #{CONSTANT_NAME.inspect} (got #{name.inspect})"
104
- end
105
-
106
- name_str.to_sym
107
- end
108
93
  end
109
94
  end
110
95
  end
@@ -1,19 +1,22 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative "names"
3
4
  require_relative "catalog/handles"
4
5
  require_relative "catalog/services"
5
6
  require_relative "catalog/snippets"
6
7
  require_relative "catalog/flags"
7
8
  require_relative "catalog/extensions"
8
9
  require_relative "catalog/mount"
10
+ require_relative "catalog/network"
9
11
  require_relative "catalog/grants"
12
+ require_relative "catalog/replacements"
10
13
 
11
14
  module Kobako
12
15
  module Catalog # :nodoc:
13
16
  # The native side carries a registered text only as UTF-8, so text read
14
17
  # as bytes is re-tagged, and bytes that are not UTF-8 are refused at
15
18
  # registration rather than failing every invocation.
16
- def self.to_utf8!(text, what)
19
+ def self.to_utf8(text, what)
17
20
  utf8 = text.dup.force_encoding(Encoding::UTF_8)
18
21
  raise ArgumentError, "#{what} must be UTF-8 text" unless utf8.valid_encoding?
19
22
 
@@ -4,8 +4,10 @@ require_relative "error"
4
4
 
5
5
  module Kobako
6
6
  module Codec
7
- module Utils # :nodoc:
8
- def self.assert_utf8!(string, label)
7
+ # What the codec refuses as it reads a value off the wire, each refusal
8
+ # raised as a Codec error.
9
+ module Boundary # :nodoc:
10
+ def self.assert_utf8(string, label)
9
11
  return if string.valid_encoding?
10
12
 
11
13
  raise InvalidEncodingError, "#{label} is not valid UTF-8"
@@ -14,7 +16,7 @@ module Kobako
14
16
  # Only for a value object built outside a Decoder.decode block, whose
15
17
  # rescue already maps the same way; a host-layer +ArgumentError+
16
18
  # elsewhere should propagate unchanged.
17
- def self.with_boundary
19
+ def self.within
18
20
  yield
19
21
  rescue ::ArgumentError => e
20
22
  raise InvalidTypeError, e.message
@@ -4,18 +4,18 @@ require "msgpack"
4
4
 
5
5
  require_relative "error"
6
6
  require_relative "ext_types"
7
- require_relative "utils"
7
+ require_relative "boundary"
8
8
 
9
9
  module Kobako
10
10
  module Codec
11
11
  module Decoder # :nodoc:
12
12
  # The block runs inside this method's rescue, so a Value Object built
13
13
  # from the decoded payload reports a broken invariant as
14
- # InvalidTypeError without its own Utils.with_boundary.
14
+ # InvalidTypeError without its own Boundary.within.
15
15
  def self.decode(bytes)
16
- ValueBudget.assert_within!(bytes, State.current.value_budget)
16
+ ValueBudget.assert_within(bytes, State.current.value_budget)
17
17
  value = FACTORY.load(bytes.b)
18
- validate_utf8!(value)
18
+ validate_utf8(value)
19
19
  block_given? ? yield(value) : value
20
20
  # msgpack gem raises the format/type errors below; +ArgumentError+
21
21
  # covers a yielded block's Value Object invariants — a wire violation
@@ -30,23 +30,23 @@ module Kobako
30
30
  raise TruncatedInputError, e.message
31
31
  end
32
32
 
33
- # +str+ family payloads must be UTF-8
34
- # (docs/wire/payload-msgpack.md § Text and Bytes). The msgpack gem
33
+ # +str+ family payloads must be UTF-8, since a sender carries bytes
34
+ # that are not UTF-8 as +bin+. The msgpack gem
35
35
  # returns UTF-8-tagged Strings for
36
36
  # str family but does not validate the bytes; +bin+ family decodes
37
37
  # to ASCII-8BIT. Walk the tree once and reject invalid UTF-8 in any
38
- # str-typed leaf via Utils.assert_utf8!.
38
+ # str-typed leaf via Boundary.assert_utf8.
39
39
  class << self
40
40
  private
41
41
 
42
- def validate_utf8!(value)
42
+ def validate_utf8(value)
43
43
  case value
44
- when String then Utils.assert_utf8!(value, "str payload") if value.encoding == Encoding::UTF_8
45
- when Array then value.each { |v| validate_utf8!(v) }
44
+ when String then Boundary.assert_utf8(value, "str payload") if value.encoding == Encoding::UTF_8
45
+ when Array then value.each { |v| validate_utf8(v) }
46
46
  when Hash
47
47
  value.each do |key, val|
48
- validate_utf8!(key)
49
- validate_utf8!(val)
48
+ validate_utf8(key)
49
+ validate_utf8(val)
50
50
  end
51
51
  end
52
52
  end
@@ -3,20 +3,18 @@
3
3
  require "msgpack"
4
4
 
5
5
  require_relative "error"
6
- require_relative "utils"
6
+ require_relative "boundary"
7
7
  require_relative "state"
8
8
  require_relative "../handle"
9
9
 
10
10
  module Kobako
11
11
  module Codec # :nodoc:
12
12
  module ExtTypes # :nodoc:
13
- # MessagePack ext type code reserved for Symbol
14
- # (docs/wire/payload-msgpack.md § ext 0x00 — Symbol). Module-private —
13
+ # MessagePack ext type code reserved for Symbol. Module-private —
15
14
  # mirrors +codec::EXT_SYMBOL+ on the
16
15
  # Rust side.
17
16
  EXT_SYMBOL = 0x00
18
- # MessagePack ext type code reserved for Capability Handle
19
- # (docs/wire/payload-msgpack.md § ext 0x01 — Handle). Module-private —
17
+ # MessagePack ext type code reserved for Capability Handle. Module-private —
20
18
  # mirrors +codec::EXT_HANDLE+ on the
21
19
  # Rust side.
22
20
  EXT_HANDLE = 0x01
@@ -51,7 +49,7 @@ module Kobako
51
49
  # unpacker would otherwise apply to invalid bytes.
52
50
  def unpack_symbol(payload)
53
51
  name = payload.b.force_encoding(Encoding::UTF_8)
54
- Utils.assert_utf8!(name, "Symbol payload")
52
+ Boundary.assert_utf8(name, "Symbol payload")
55
53
  name.to_sym
56
54
  end
57
55
 
@@ -68,7 +66,7 @@ module Kobako
68
66
  raise InvalidTypeError, "Handle payload must be 4 bytes, got #{bytes.bytesize}" unless bytes.bytesize == 4
69
67
 
70
68
  id = bytes.unpack1("N") # : Integer
71
- Codec::Utils.with_boundary { Kobako::Handle.restore(id) }
69
+ Codec::Boundary.within { Kobako::Handle.restore(id) }
72
70
  end
73
71
 
74
72
  def register_symbol(factory)
@@ -8,8 +8,7 @@ module Kobako
8
8
  module HandleWalk # :nodoc:
9
9
  # Inclusive Integer range the msgpack gem encodes without raising
10
10
  # +RangeError+ at encode time — signed +int 64+ minimum through
11
- # unsigned +uint 64+ maximum (docs/wire/payload-msgpack.md § Integer
12
- # Range).
11
+ # unsigned +uint 64+ maximum, the range every wire Integer fits.
13
12
  # Anchored as a +Range+ so #primitive_type? stays a single
14
13
  # dispatch line. This is the codec's encode domain — not to
15
14
  # be confused with the Handle id range, which lives on
@@ -17,8 +16,7 @@ module Kobako
17
16
  # represents a different concept entirely.
18
17
  MSGPACK_INT_RANGE = (-(2**63)..((2**64) - 1))
19
18
 
20
- # Whether +value+ falls in the codec's type set
21
- # (docs/wire/payload-msgpack.md § Type Mapping). The +depth+ bound
19
+ # Whether +value+ falls in the codec's closed type set. The +depth+ bound
22
20
  # makes a self-referential container —
23
21
  # reachable as a cyclic Hash key on the +#run+ argument path — read as
24
22
  # non-representable rather than looping.
@@ -28,22 +26,9 @@ module Kobako
28
26
  primitive_type?(value) || container_representable?(value, depth)
29
27
  end
30
28
 
31
- # Only Hash values are wrapped: a non-representable key raises rather
32
- # than crossing as a token the guest→host restore walk could not
33
- # round-trip.
34
- def self.deep_wrap(value, handles, depth = 0)
35
- guard_nesting!(depth)
36
- case value
37
- when ::Array then value.map { |element| deep_wrap(element, handles, depth + 1) }
38
- when ::Hash then deep_wrap_hash(value, handles, depth)
39
- else
40
- representable?(value) ? value : handles.alloc(value)
41
- end
42
- end
43
-
44
- # The inverse of #deep_wrap. A Handle here was decoded off the wire,
45
- # never forged by the guest, and +handles.fetch+ refuses an id with no
46
- # live binding.
29
+ # Each Handle a decoded value holds, as the object it stands for. A
30
+ # Handle here was decoded off the wire, never forged by the guest, and
31
+ # +handles.fetch+ refuses an id with no live binding.
47
32
  def self.deep_restore(value, handles)
48
33
  case value
49
34
  when ::Array then value.map { |element| deep_restore(element, handles) }
@@ -61,33 +46,6 @@ module Kobako
61
46
  class << self
62
47
  private
63
48
 
64
- # A reference cycle necessarily trips the nesting bound, so a +#run+
65
- # argument fails as a clean +Kobako::SandboxError+ rather than an
66
- # unbounded host recursion.
67
- def guard_nesting!(depth)
68
- return unless depth > MAX_NESTING_DEPTH
69
-
70
- raise Kobako::SandboxError,
71
- "a #run argument nests deeper than #{MAX_NESTING_DEPTH} levels within the Run payload and " \
72
- "cannot cross the sandbox boundary (possible reference cycle)"
73
- end
74
-
75
- # A stateful object may cross the boundary as a Hash value but not as
76
- # a key — the one deliberate asymmetry with the guest→host restore
77
- # walk, which resolves Handle keys the guest built.
78
- def deep_wrap_hash(hash, handles, depth)
79
- wrapped = {} # : Hash[untyped, untyped]
80
- hash.each do |key, val|
81
- unless representable?(key, depth + 1)
82
- raise Kobako::SandboxError,
83
- "a Hash passed to #run has a key that cannot cross the sandbox boundary " \
84
- "(#{key.class}); only wire-representable values may be Hash keys"
85
- end
86
- wrapped[key] = deep_wrap(val, handles, depth + 1)
87
- end
88
- wrapped
89
- end
90
-
91
49
  def primitive_type?(value)
92
50
  case value
93
51
  when ::NilClass, ::TrueClass, ::FalseClass, ::Float, ::String, ::Symbol, Kobako::Handle then true
@@ -9,12 +9,12 @@ module Kobako
9
9
  module Nesting # :nodoc:
10
10
  # Raise InvalidTypeError when +value+ nests past MAX_NESTING_DEPTH; a
11
11
  # value nested exactly to the bound passes.
12
- def self.assert_within_bound!(value, depth = 0)
12
+ def self.assert_within_bound(value, depth = 0)
13
13
  case value
14
- when ::Array then assert_members_within_bound!(value, depth)
14
+ when ::Array then assert_members_within_bound(value, depth)
15
15
  when ::Hash
16
- assert_members_within_bound!(value.keys, depth)
17
- assert_members_within_bound!(value.values, depth)
16
+ assert_members_within_bound(value.keys, depth)
17
+ assert_members_within_bound(value.values, depth)
18
18
  end
19
19
  end
20
20
 
@@ -22,7 +22,7 @@ module Kobako
22
22
  # level deeper. A member is matched by class rather than asked about
23
23
  # itself — it may be a BasicObject — and only one that could be a
24
24
  # container is walked into.
25
- def self.assert_members_within_bound!(members, depth)
25
+ def self.assert_members_within_bound(members, depth)
26
26
  return if members.empty?
27
27
  if depth >= MAX_NESTING_DEPTH
28
28
  raise InvalidTypeError,
@@ -30,9 +30,9 @@ module Kobako
30
30
  end
31
31
  return unless members.any?(::Enumerable)
32
32
 
33
- members.grep(::Enumerable) { |member| assert_within_bound!(member, depth + 1) }
33
+ members.grep(::Enumerable) { |member| assert_within_bound(member, depth + 1) }
34
34
  end
35
- private_class_method :assert_members_within_bound!
35
+ private_class_method :assert_members_within_bound
36
36
  end
37
37
  end
38
38
  end