summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoro <o@immerda.ch>2011-06-26 02:15:25 +0200
committero <o@immerda.ch>2011-06-26 02:15:25 +0200
commit8b325e7d08b267be508dbb5fc0b655fdcd447216 (patch)
tree31e77e2ab250a46cdd0545a83d1cf7426ecf0140
parent39260e5764332d0e3989c75dcbdff4448809ad6b (diff)
fix integer precision
-rw-r--r--lib/fpg/io/radix64.rb14
-rw-r--r--lib/fpg/parse/packet.rb6
-rw-r--r--spec/radix64_spec.rb4
3 files changed, 12 insertions, 12 deletions
diff --git a/lib/fpg/io/radix64.rb b/lib/fpg/io/radix64.rb
index 4ecdaf3..b2a06d3 100644
--- a/lib/fpg/io/radix64.rb
+++ b/lib/fpg/io/radix64.rb
@@ -5,7 +5,7 @@ module FPG
@char_table ||= "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".each_byte.collect.to_a
end
def pad
- pad_s.unpack("C1!").first
+ pad_s.unpack("C1").first
end
def pad_s
"="
@@ -20,28 +20,28 @@ module FPG
char_table[six]
end
def quad2bytes(quad)
- q = (quad.unpack("C4!").collect { |v| char2six(v) }).to_a
+ q = (quad.unpack("C4").collect { |v| char2six(v) }).to_a
[ (q[0]<<2)+(q[1]>>4), ((q[1]<<4)%256)+(q[2]>>2), ((q[2]<<6)%256)+q[3] ]
end
def padded_quad2bytes(quad)
if quad[2] == pad_s then
- q = quad.unpack("C2!").collect { |v| char2six(v) }
+ q = quad.unpack("C2").collect { |v| char2six(v) }
[ (q[0]<<2)+(q[1]>>4), ((q[1]<<4)%256)>>4 ]
else
- q = quad.unpack("C3!").collect { |v| char2six(v) }
+ q = quad.unpack("C3").collect { |v| char2six(v) }
[ (q[0]<<2)+(q[1]>>4), ((q[1]<<4)%256)+(q[2]>>2), ((q[2]<<6)%256) ]
end
end
def bytes2quad(bytes)
[ six2char(bytes[0]>>2), six2char(((bytes[0]<<4)%64)+(bytes[1]>>4)),
- six2char(((bytes[1]<<2)%64)+(bytes[2]>>6)), six2char(bytes[2]%64) ].pack("C4!")
+ six2char(((bytes[1]<<2)%64)+(bytes[2]>>6)), six2char(bytes[2]%64) ].pack("C4")
end
def bytes2padded_quad(bytes)
if bytes.length == 1
- [six2char(bytes[0]>>2), six2char((bytes[0]<<4)%64), pad, pad].pack("C4!")
+ [six2char(bytes[0]>>2), six2char((bytes[0]<<4)%64), pad, pad].pack("C4")
elsif bytes.length == 2
[ six2char(bytes[0]>>2), six2char(((bytes[0]<<4)%64)+(bytes[1]>>4)),
- six2char((bytes[1]<<2)%64), pad].pack("C4!")
+ six2char((bytes[1]<<2)%64), pad].pack("C4")
end
end
def de_armor( stream )
diff --git a/lib/fpg/parse/packet.rb b/lib/fpg/parse/packet.rb
index e421a80..b35f4ff 100644
--- a/lib/fpg/parse/packet.rb
+++ b/lib/fpg/parse/packet.rb
@@ -33,14 +33,14 @@ module FPG
first = stream.getbyte
return first if first < 192
return ((first-192)<<8)+stream.getbyte+192 if first < 224
- return (first+stream.gets(3)).unpack("N")[0] if first == 255
+ return (first+stream.read(3)).unpack("N")[0] if first == 255
self.partial_length= true
return 1<<(first&0x1f)
end
def old_packet_size(tag)
return stream.getbyte if tag == 0
- return stream.gets(2).unpack("n")[0] if tag == 1
- return stream.gets(4).unpack("N")[0] if tag == 2
+ return stream.read(2).unpack("n")[0] if tag == 1
+ return stream.read(4).unpack("N")[0] if tag == 2
#tag==3 => size is until eof
#TODO this seems a bit cumbersome
current_pos = stream.pos
diff --git a/spec/radix64_spec.rb b/spec/radix64_spec.rb
index 81c9bb6..5f66387 100644
--- a/spec/radix64_spec.rb
+++ b/spec/radix64_spec.rb
@@ -24,7 +24,7 @@ describe Radix64 do
@armored_sec.read.should == @in
end
it "should correctly dearmor a public key" do
- @radix.de_armor( @armored_pub ) { |byte| @in << [byte].pack("C1!") }
+ @radix.de_armor( @armored_pub ) { |byte| @in << [byte].pack("C1") }
@binary_pub.read.should == @in
end
it "should de/-armor to the same key" do
@@ -38,7 +38,7 @@ describe Radix64 do
@radix.armor( @binary_sec ) { |line| in_str << line }
in_str << "\n"
in_str.rewind
- @radix.de_armor( in_str ) { |byte| @in2 << [byte].pack("C1!") }
+ @radix.de_armor( in_str ) { |byte| @in2 << [byte].pack("C1") }
@binary_sec.rewind
@binary_sec.read.should == @in2
end