Module: Binenc::Java::DataConversion
- Included in:
- ASN1Object, SBLFactory
- Defined in:
- lib/binenc/data_conversion.rb
Class Method Summary collapse
-
.included(klass) ⇒ Object
Add the methods to class level.
Instance Method Summary collapse
- #from_b64(str) ⇒ Object
-
#from_hex(str) ⇒ Object
end to_hex.
-
#to_b64(bin) ⇒ Object
end from_hex.
-
#to_b64_mime(bin) ⇒ Object
end to_b64.
- #to_bin(str) ⇒ Object
- #to_hex(bin) ⇒ Object
- #to_java_bytes(val, encoding = nil) ⇒ Object
-
#to_str(bin) ⇒ Object
end from_b64.
Class Method Details
.included(klass) ⇒ Object
Add the methods to class level
65 66 67 68 69 |
# File 'lib/binenc/data_conversion.rb', line 65 def self.included(klass) klass.class_eval " extend Binenc::Java::DataConversion\n END\nend\n" |
Instance Method Details
#from_b64(str) ⇒ Object
26 27 28 |
# File 'lib/binenc/data_conversion.rb', line 26 def from_b64(str) java.util.Base64.decoder.decode(str) end |
#from_hex(str) ⇒ Object
end to_hex
11 12 13 |
# File 'lib/binenc/data_conversion.rb', line 11 def from_hex(str) org.bouncycastle.util.encoders.Hex.decode(str) end |
#to_b64(bin) ⇒ Object
end from_hex
16 17 18 |
# File 'lib/binenc/data_conversion.rb', line 16 def to_b64(bin) String.from_java_bytes(java.util.Base64.encoder.encode(bin)) end |
#to_b64_mime(bin) ⇒ Object
end to_b64
22 23 24 |
# File 'lib/binenc/data_conversion.rb', line 22 def to_b64_mime(bin) String.from_java_bytes(java.util.Base64.mime_encoder.encode(bin)) end |
#to_bin(str) ⇒ Object
39 40 41 42 43 44 45 |
# File 'lib/binenc/data_conversion.rb', line 39 def to_bin(str) if str.nil? ::Java::byte[0].new else str.to_java.getBytes end end |
#to_hex(bin) ⇒ Object
6 7 8 |
# File 'lib/binenc/data_conversion.rb', line 6 def to_hex(bin) String.from_java_bytes(org.bouncycastle.util.encoders.Hex.encode(bin)) end |
#to_java_bytes(val, encoding = nil) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/binenc/data_conversion.rb', line 47 def to_java_bytes(val, encoding = nil) case val when String val.to_java_bytes when java.lang.String if not_empty?(encoding) val.getBytes(encoding) else val.getBytes end else val end end |
#to_str(bin) ⇒ Object
end from_b64
31 32 33 34 35 36 37 |
# File 'lib/binenc/data_conversion.rb', line 31 def to_str(bin) if bin.is_a?(::Java::byte[]) String.from_java_bytes(bin) else bin end end |