Class: StunClient::Utilities
- Inherits:
-
Object
- Object
- StunClient::Utilities
- Defined in:
- lib/stun-client/generic/utilities.rb
Overview
Contains useful functions used by different parts of the STUN client implementation. These functions can act independently of the context.
Class Method Summary collapse
-
.generate_txid(bits) ⇒ Object
Generates a random transaction ID.
-
.sanitize_string(str) ⇒ Object
Attempts to sanitize a string before it is processed further.
Class Method Details
.generate_txid(bits) ⇒ Object
Generates a random transaction ID. It contains the characters 0-9 and a-f.
10 11 12 13 14 15 16 |
# File 'lib/stun-client/generic/utilities.rb', line 10 def self.generate_txid bits bytes = bits / 8 raise 'A TxID with bits not divisible by eight is not possible.' if bits % 8 != 0 bytes /= 2 # as .hex doubles the length return SecureRandom.hex(bytes) end |
.sanitize_string(str) ⇒ Object
Attempts to sanitize a string before it is processed further. This tries to escape some security holes. For sanitizing the function ‘dump` is used.
24 25 26 |
# File 'lib/stun-client/generic/utilities.rb', line 24 def self.sanitize_string str return str.dump[1...-1] end |