pub(crate) unsafe fn _ykpiv_get_version(state: *mut YubiKey, p_version: *mut Version) -> ErrorKind {
    let mut data = [0u8; 261];
    let mut recv_len = data.len() as u32;
    let mut sw: i32 = 0;
    let res: ErrorKind;

    if state.is_null() {
        return ErrorKind::ArgumentError;
    }

    // get version from state if already from device
    if (*state).ver.major != 0 || (*state).ver.minor != 0 || (*state).ver.patch != 0 {
        if !p_version.is_null() {
            // TODO(tarcieri): use real references instead of pointers and memcpy!!!
            #[allow(trivial_casts)]
            memcpy(
                p_version as *mut c_void,
                &(*state).ver as *const Version as *const c_void,
                mem::size_of::<Version>(),
            );
        }

        return ErrorKind::Ok;
    }

    // get version from device
    let mut apdu = APDU::default();
    apdu.ins = YKPIV_INS_GET_VERSION;

    res = _send_data(state, &mut apdu, data.as_mut_ptr(), &mut recv_len, &mut sw);

    if res != ErrorKind::Ok {
        return res;
    }

    if sw != SW_SUCCESS {
        return ErrorKind::GenericError;
    }

    if recv_len < 3 {
        return ErrorKind::SizeError;
    }

    (*state).ver.major = data[0];
    (*state).ver.minor = data[1];
    (*state).ver.patch = data[2];

    if !p_version.is_null() {
        // TODO(tarcieri): use real references instead of pointers and memcpy!!!
        #[allow(trivial_casts)]
        memcpy(
            p_version as *mut c_void,
            &(*state).ver as (*const Version) as (*const c_void),
            mem::size_of::<Version>(),
        );
    }

    ErrorKind::Ok
}
/// Get the version of the PIV application installed on the YubiKey
Get the version of the PIV application installed on the YubiKey
Get the version of the PIV application installed on the YubiKey
pub(crate) unsafe fn _ykpiv_get_version(state: *mut YubiKey, p_version: *mut Version) -> ErrorKind {
    let mut data = [0u8; 261];
    let mut recv_len = data.len() as u32;
    let mut sw: i32 = 0;
    let res: ErrorKind;
    if state.is_null() {
        return ErrorKind::ArgumentError;
    }
    // get version from state if already from device
    if (*state).ver.major != 0 || (*state).ver.minor != 0 || (*state).ver.patch != 0 {
        if !p_version.is_null() {
            // TODO(tarcieri): use real references instead of pointers and memcpy!!!
            #[allow(trivial_casts)]
            memcpy(
                p_version as *mut c_void,
                &(*state).ver as *const Version as *const c_void,
                mem::size_of::<Version>(),
            );
        }
        return ErrorKind::Ok;
    }
    // get version from device
    let mut apdu = APDU::default();
    apdu.ins = YKPIV_INS_GET_VERSION;
    res = _send_data(state, &mut apdu, data.as_mut_ptr(), &mut recv_len, &mut sw);
    if res != ErrorKind::Ok {
        return res;
    }
    if sw != SW_SUCCESS {
        return ErrorKind::GenericError;
    }
    if recv_len < 3 {
        return ErrorKind::SizeError;
    }
    (*state).ver.major = data[0];
    (*state).ver.minor = data[1];
    (*state).ver.patch = data[2];
    if !p_version.is_null() {
        // TODO(tarcieri): use real references instead of pointers and memcpy!!!
        #[allow(trivial_casts)]
        memcpy(
            p_version as *mut c_void,
            &(*state).ver as (*const Version) as (*const c_void),
            mem::size_of::<Version>(),
        );
    }
    ErrorKind::Ok
}
pub ( crate ) unsafe fn _ykpiv_get_version ( state : * mut YubiKey , p_version : * mut Version ) -> ErrorKind { let mut data = [ 0u8 ; 261 ] ; let mut recv_len = data . len ( ) as u32 ; let mut sw : i32 = 0 ; let res : ErrorKind ; if state . is_null ( ) { return ErrorKind :: ArgumentError ; } // get version from state if already from device if ( * state ) . ver . major != 0 || ( * state ) . ver . minor != 0 || ( * state ) . ver . patch != 0 { if ! p_version . is_null ( ) { // TODO(tarcieri): use real references instead of pointers and memcpy!!! # [ allow ( trivial_casts ) ] memcpy ( p_version as * mut c_void , & ( * state ) . ver as * const Version as * const c_void , mem :: size_of :: < Version > ( ) , ) ; } return ErrorKind :: Ok ; } // get version from device let mut apdu = APDU :: default ( ) ; apdu . ins = YKPIV_INS_GET_VERSION ; res = _send_data ( state , & mut apdu , data . as_mut_ptr ( ) , & mut recv_len , & mut sw ) ; if res != ErrorKind :: Ok { return res ; } if sw != SW_SUCCESS { return ErrorKind :: GenericError ; } if recv_len < 3 { return ErrorKind :: SizeError ; } ( * state ) . ver . major = data [ 0 ] ; ( * state ) . ver . minor = data [ 1 ] ; ( * state ) . ver . patch = data [ 2 ] ; if ! p_version . is_null ( ) { // TODO(tarcieri): use real references instead of pointers and memcpy!!! # [ allow ( trivial_casts ) ] memcpy ( p_version as * mut c_void , & ( * state ) . ver as ( * const Version ) as ( * const c_void ) , mem :: size_of :: < Version > ( ) , ) ; } ErrorKind :: Ok }
Get the version of the PIV application installed on the YubiKey
Get the version of the PIV application installed on the YubiKey
state
*mut YubiKey
p_version
*mut Version