blob: b8a1c734414e78d5a5cdf2d1c5380b675bac80cf (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
# coding: ASCII-8BIT
class ASN1Kit::Boolean < ASN1Kit::Type
asn1_tag :IMPLICIT, :UNIVERSAL, 1
asn1_alias "BOOLEAN"
def initialize(value)
self.value = value
end
def value
@value
end
def value=(value)
if value != true && value != false
raise TypeError, "illegal value for BOOLEAN: %p" % value
end
@value = value
end
def to_der
der_header(1) << (value ? "\xff" : "\x00")
end
def self.from_ber(ber)
content = check_ber_header(ber)
if content.bytesize != 1
raise EncodingError, "invalid content length for BOOLEAN"
end
new(content != "\x00")
end
def ==(other)
other.class <= ASN1Kit::Boolean && value == other.value
end
private def inspect_inner
@value ? "TRUE" : "FALSE"
end
end
|