45ba342f57
Includes changes to the original C code needed for `corrode` to accept the input. There were a lot of problems with APDU fields. These need to be copied into the translated Rust code and fixed up manually. Code otherwise contains the raw `corrode` output.
170 lines
5.1 KiB
Rust
170 lines
5.1 KiB
Rust
extern {
|
|
fn strcmp(__s1 : *const u8, __s2 : *const u8) -> i32;
|
|
fn strcspn(__s : *const u8, __charset : *const u8) -> usize;
|
|
fn strncmp(__s1 : *const u8, __s2 : *const u8, __n : usize) -> i32;
|
|
fn strspn(__s : *const u8, __charset : *const u8) -> usize;
|
|
}
|
|
|
|
unsafe extern fn my_strverscmp(
|
|
mut s1 : *const u8, mut s2 : *const u8
|
|
) -> i32 {
|
|
let mut _currentBlock;
|
|
static mut digits : *const u8 = (*b"0123456789\0").as_ptr();
|
|
let mut p1 : usize;
|
|
let mut p2 : usize;
|
|
p1 = strcspn(s1,digits);
|
|
p2 = strcspn(s2,digits);
|
|
'loop1: loop {
|
|
if !(p1 == p2 && (*s1.offset(
|
|
p1 as (isize)
|
|
) as (i32) != b'\0' as (i32)) && (*s2.offset(
|
|
p2 as (isize)
|
|
) as (i32) != b'\0' as (i32))) {
|
|
_currentBlock = 2;
|
|
break;
|
|
}
|
|
let mut ret : i32;
|
|
let mut lz1 : i32;
|
|
let mut lz2 : i32;
|
|
if {
|
|
ret = strncmp(s1,s2,p1);
|
|
ret
|
|
} != 0i32 {
|
|
_currentBlock = 37;
|
|
break;
|
|
}
|
|
s1 = s1.offset(p1 as (isize));
|
|
s2 = s2.offset(p2 as (isize));
|
|
lz1 = {
|
|
lz2 = 0i32;
|
|
lz2
|
|
};
|
|
if *s1 as (i32) == b'0' as (i32) {
|
|
lz1 = 1i32;
|
|
}
|
|
if *s2 as (i32) == b'0' as (i32) {
|
|
lz2 = 1i32;
|
|
}
|
|
if lz1 > lz2 {
|
|
_currentBlock = 36;
|
|
break;
|
|
}
|
|
if lz1 < lz2 {
|
|
_currentBlock = 35;
|
|
break;
|
|
}
|
|
if lz1 == 1i32 {
|
|
_currentBlock = 11;
|
|
} else {
|
|
_currentBlock = 23;
|
|
}
|
|
'loop11: loop {
|
|
if _currentBlock == 11 {
|
|
if *s1 as (i32) == b'0' as (i32) && (*s2 as (i32) == b'0' as (i32)) {
|
|
s1 = s1.offset(1isize);
|
|
s2 = s2.offset(1isize);
|
|
_currentBlock = 11;
|
|
} else {
|
|
p1 = strspn(s1,digits);
|
|
p2 = strspn(s2,digits);
|
|
if p1 == 0usize && (p2 > 0usize) {
|
|
_currentBlock = 33;
|
|
break 'loop1;
|
|
}
|
|
if p2 == 0usize && (p1 > 0usize) {
|
|
_currentBlock = 32;
|
|
break 'loop1;
|
|
}
|
|
if *s1 as (i32) != *s2 as (i32) && (*s1 as (i32) != b'0' as (i32)) && (*s2 as (i32) != b'0' as (i32)) {
|
|
if p1 < p2 {
|
|
_currentBlock = 31;
|
|
break 'loop1;
|
|
}
|
|
if p1 > p2 {
|
|
_currentBlock = 30;
|
|
break 'loop1;
|
|
} else {
|
|
_currentBlock = 23;
|
|
}
|
|
} else {
|
|
if p1 < p2 {
|
|
ret = strncmp(s1,s2,p1);
|
|
} else if p1 > p2 {
|
|
ret = strncmp(s1,s2,p2);
|
|
}
|
|
if ret != 0i32 {
|
|
_currentBlock = 20;
|
|
break 'loop1;
|
|
} else {
|
|
_currentBlock = 23;
|
|
}
|
|
}
|
|
}
|
|
} else {
|
|
p1 = strspn(s1,digits);
|
|
p2 = strspn(s2,digits);
|
|
if p1 < p2 {
|
|
_currentBlock = 29;
|
|
break 'loop1;
|
|
} else {
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
if p1 > p2 {
|
|
_currentBlock = 28;
|
|
break;
|
|
}
|
|
if {
|
|
ret = strncmp(s1,s2,p1);
|
|
ret
|
|
} != 0i32 {
|
|
_currentBlock = 27;
|
|
break;
|
|
}
|
|
s1 = s1.offset(p1 as (isize));
|
|
s2 = s2.offset(p2 as (isize));
|
|
p1 = strcspn(s1,digits);
|
|
p2 = strcspn(s2,digits);
|
|
}
|
|
if _currentBlock == 2 {
|
|
strcmp(s1,s2)
|
|
} else if _currentBlock == 20 {
|
|
ret
|
|
} else if _currentBlock == 27 {
|
|
ret
|
|
} else if _currentBlock == 28 {
|
|
1i32
|
|
} else if _currentBlock == 29 {
|
|
-1i32
|
|
} else if _currentBlock == 30 {
|
|
-1i32
|
|
} else if _currentBlock == 31 {
|
|
1i32
|
|
} else if _currentBlock == 32 {
|
|
-1i32
|
|
} else if _currentBlock == 33 {
|
|
1i32
|
|
} else if _currentBlock == 35 {
|
|
1i32
|
|
} else if _currentBlock == 36 {
|
|
-1i32
|
|
} else {
|
|
ret
|
|
}
|
|
}
|
|
|
|
#[no_mangle]
|
|
pub unsafe extern fn ykpiv_check_version(
|
|
mut req_version : *const u8
|
|
) -> *const u8 {
|
|
if req_version.is_null() || my_strverscmp(
|
|
req_version,
|
|
(*b"@VERSION@\0").as_ptr()
|
|
) <= 0i32 {
|
|
(*b"@VERSION@\0").as_ptr()
|
|
} else {
|
|
0i32 as (*mut ::std::os::raw::c_void) as (*const u8)
|
|
}
|
|
}
|