# HG changeset patch # User Alessio Caiazza # Date 1266315674 -3600 # Node ID c9f74665d8ef42057396d66d91167216dc46d2b4 # Parent ffb42b5dd16250ebd094a8c78848f578aa80bb60 Fixed some bugs in hex decoding ( fixes #1 and #2 ) diff -r ffb42b5dd16250ebd094a8c78848f578aa80bb60 -r c9f74665d8ef42057396d66d91167216dc46d2b4 .hgignore --- a/.hgignore Wed Feb 03 23:10:12 2010 +0100 +++ b/.hgignore Tue Feb 16 11:21:14 2010 +0100 @@ -21,4 +21,5 @@ .*\#.*\#$ ^tmp/*$ ^script/*$ -^doc/*$ \ No newline at end of file +^doc/*$ +^pkg/*$ \ No newline at end of file diff -r ffb42b5dd16250ebd094a8c78848f578aa80bb60 -r c9f74665d8ef42057396d66d91167216dc46d2b4 CHANGELOG --- a/CHANGELOG Wed Feb 03 23:10:12 2010 +0100 +++ b/CHANGELOG Tue Feb 16 11:21:14 2010 +0100 @@ -1,3 +1,5 @@ +v0.1.1. fixed some bugs in hex decoding. + v0.1.0. modhex installed as binary. v0.0.1. First release \ No newline at end of file diff -r ffb42b5dd16250ebd094a8c78848f578aa80bb60 -r c9f74665d8ef42057396d66d91167216dc46d2b4 YubiRuby.gemspec --- a/YubiRuby.gemspec Wed Feb 03 23:10:12 2010 +0100 +++ b/YubiRuby.gemspec Tue Feb 16 11:21:14 2010 +0100 @@ -2,11 +2,11 @@ Gem::Specification.new do |s| s.name = %q{YubiRuby} - s.version = "0.1.0" + s.version = "0.1.1" s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version= s.authors = ["Alessio Caiazza"] - s.date = %q{2010-02-03} + s.date = %q{2010-02-16} s.default_executable = %q{modhex} s.description = %q{Yubikey integration - diff -r ffb42b5dd16250ebd094a8c78848f578aa80bb60 -r c9f74665d8ef42057396d66d91167216dc46d2b4 ext/libyubikey/libyubikey.c --- a/ext/libyubikey/libyubikey.c Wed Feb 03 23:10:12 2010 +0100 +++ b/ext/libyubikey/libyubikey.c Tue Feb 16 11:21:14 2010 +0100 @@ -371,9 +371,13 @@ VALUE ary = rb_ary_new2(YUBIKEY_BLOCK_SIZE); for (i = 0; i < YUBIKEY_BLOCK_SIZE; i++) { - VALUE num = INT2FIX(((uint8_t*)data->token)[i]); + uint8_t c_num = ((uint8_t*)data->token)[i]; + VALUE num = INT2FIX(c_num); //invoke .to_s 16 on each number - rb_ary_store(ary, i, rb_funcall(num, rb_intern("to_s"), 1, INT2FIX(16) )); + VALUE hexed = rb_funcall(num,rb_intern("to_s"), 1, INT2FIX(16)); + if(c_num < 16) //if num < 16 prepend a '0' + hexed = rb_funcall(hexed,rb_intern("insert"), 2, INT2FIX(0),rb_str_new2("0")); + rb_ary_store(ary, i, hexed ); } return rb_funcall(ary, rb_intern("join"), 0); diff -r ffb42b5dd16250ebd094a8c78848f578aa80bb60 -r c9f74665d8ef42057396d66d91167216dc46d2b4 lib/hex.rb --- a/lib/hex.rb Wed Feb 03 23:10:12 2010 +0100 +++ b/lib/hex.rb Tue Feb 16 11:21:14 2010 +0100 @@ -48,6 +48,15 @@ def self.encode( obj ) s = obj.to_str s.unpack('U'*s.length).collect {|x| x.to_s 16}.join + rescue ArgumentError + #non UTF-8 string + s = obj.to_str + out = [] + 0.upto(s.length-1) do |i| + tmp = s[i].to_s 16 + out << (tmp.length == 1 ? "0#{tmp}" : tmp ) + end + out.join end # call-seq: