pub unsafe fn ykpiv_util_get_protected_mgm(state: *mut YubiKey, mgm: *mut YkPivMgm) -> ErrorKind {
    let mut data = [0u8; YKPIV_OBJ_MAX_SIZE];
    let mut cb_data: usize = data.len();
    let mut p_item: *mut u8 = ptr::null_mut();
    let mut cb_item: usize = 0;
    let mut res = ErrorKind::Ok;

    if state.is_null() || mgm.is_null() {
        return ErrorKind::GenericError;
    }

    if _ykpiv_begin_transaction(state) != ErrorKind::Ok {
        return ErrorKind::PcscError;
    }

    if _ykpiv_ensure_application_selected(state) == ErrorKind::Ok {
        res = _read_metadata(state, 0x88u8, data.as_mut_ptr(), &mut cb_data);

        if res != ErrorKind::Ok {
            if (*state).verbose != 0 {
                eprintln!("could not read protected data, err = {:?}", res);
            }
        } else {
            res = _get_metadata_item(
                data.as_mut_ptr(),
                cb_data,
                0x89u8,
                &mut p_item,
                &mut cb_item,
            );

            if res != ErrorKind::Ok {
                if (*state).verbose != 0 {
                    eprintln!(
                        "could not read protected mgm from metadata, err = {}",
                        res as (i32),
                    );
                }
            } else if cb_item != (*mgm).0.len() {
                if (*state).verbose != 0 {
                    eprintln!(
                        "protected data contains mgm, but is the wrong size = {}",
                        cb_item,
                    );
                }
                res = ErrorKind::AuthenticationError;
            } else {
                memcpy(
                    (*mgm).0.as_mut_ptr() as (*mut c_void),
                    p_item as (*const c_void),
                    cb_item,
                );
            }
        }
    }

    data.zeroize();
    _ykpiv_end_transaction(state);
    res
}
/// Get protected management key (MGM)
Get protected management key (MGM)
Get protected management key ( MGM )
pub unsafe fn ykpiv_util_get_protected_mgm(state: *mut YubiKey, mgm: *mut YkPivMgm) -> ErrorKind {
    let mut data = [0u8; YKPIV_OBJ_MAX_SIZE];
    let mut cb_data: usize = data.len();
    let mut p_item: *mut u8 = ptr::null_mut();
    let mut cb_item: usize = 0;
    let mut res = ErrorKind::Ok;
    if state.is_null() || mgm.is_null() {
        return ErrorKind::GenericError;
    }
    if _ykpiv_begin_transaction(state) != ErrorKind::Ok {
        return ErrorKind::PcscError;
    }
    if _ykpiv_ensure_application_selected(state) == ErrorKind::Ok {
        res = _read_metadata(state, 0x88u8, data.as_mut_ptr(), &mut cb_data);
        if res != ErrorKind::Ok {
            if (*state).verbose != 0 {
                eprintln!("could not read protected data, err = {:?}", res);
            }
        } else {
            res = _get_metadata_item(
                data.as_mut_ptr(),
                cb_data,
                0x89u8,
                &mut p_item,
                &mut cb_item,
            );
            if res != ErrorKind::Ok {
                if (*state).verbose != 0 {
                    eprintln!(
                        "could not read protected mgm from metadata, err = {}",
                        res as (i32),
                    );
                }
            } else if cb_item != (*mgm).0.len() {
                if (*state).verbose != 0 {
                    eprintln!(
                        "protected data contains mgm, but is the wrong size = {}",
                        cb_item,
                    );
                }
                res = ErrorKind::AuthenticationError;
            } else {
                memcpy(
                    (*mgm).0.as_mut_ptr() as (*mut c_void),
                    p_item as (*const c_void),
                    cb_item,
                );
            }
        }
    }
    data.zeroize();
    _ykpiv_end_transaction(state);
    res
}
pub unsafe fn ykpiv_util_get_protected_mgm ( state : * mut YubiKey , mgm : * mut YkPivMgm ) -> ErrorKind { let mut data = [ 0u8 ; YKPIV_OBJ_MAX_SIZE ] ; let mut cb_data : usize = data . len ( ) ; let mut p_item : * mut u8 = ptr :: null_mut ( ) ; let mut cb_item : usize = 0 ; let mut res = ErrorKind :: Ok ; if state . is_null ( ) || mgm . is_null ( ) { return ErrorKind :: GenericError ; } if _ykpiv_begin_transaction ( state ) != ErrorKind :: Ok { return ErrorKind :: PcscError ; } if _ykpiv_ensure_application_selected ( state ) == ErrorKind :: Ok { res = _read_metadata ( state , 0x88u8 , data . as_mut_ptr ( ) , & mut cb_data ) ; if res != ErrorKind :: Ok { if ( * state ) . verbose != 0 { eprintln ! ( " " res ) ; } } else { res = _get_metadata_item ( data . as_mut_ptr ( ) , cb_data , 0x89u8 , & mut p_item , & mut cb_item , ) ; if res != ErrorKind :: Ok { if ( * state ) . verbose != 0 { eprintln ! ( " " res as ( i32 ) ) ; } } else if cb_item != ( * mgm ) . 0 . len ( ) { if ( * state ) . verbose != 0 { eprintln ! ( " " cb_item ) ; } res = ErrorKind :: AuthenticationError ; } else { memcpy ( ( * mgm ) . 0 . as_mut_ptr ( ) as ( * mut c_void ) , p_item as ( * const c_void ) , cb_item , ) ; } } } data . zeroize ( ) ; _ykpiv_end_transaction ( state ) ; res }
Get protected management key (MGM)
Get protected management key ( MGM )
state
*mut YubiKey
mgm
*mut YkPivMgm