pub fn build_blob(credentials: &Credentials, device_id: &str) -> String {
    let mut blob: Vec<u8> = Vec::new();
    // 'I'
    write_int(0x49, &mut blob);
    // username
    write_bytes(credentials.username.as_bytes(), &mut blob);
    // 'P'
    write_int(0x50, &mut blob);
    // auth_type
    write_int(credentials.auth_type as u32, &mut blob);
    // 'Q'
    write_int(0x51, &mut blob);
    // auth_data
    write_bytes(&credentials.auth_data, &mut blob);
    // Padding
    let n_zeros = 16 - (blob.len() % 16) - 1;
    blob.extend(vec![0; n_zeros]);
    blob.push(n_zeros as u8 + 1);

    let l = blob.len();
    for i in (0..l - 0x10).rev() {
        blob[l - i - 1] ^= blob[l - i - 0x11];
    }

    let secret = Sha1::digest(device_id.as_bytes());

    let key = {
        let mut key = [0u8; 24];
        pbkdf2::pbkdf2::<Hmac<Sha1>>(
            &secret,
            credentials.username.as_bytes(),
            0x100,
            &mut key[0..20],
        );

        let hash = Sha1::digest(&key[..20]);
        key[..20].copy_from_slice(&hash);
        key[23] = 20u8;
        key
    };

    let encrypted_blob = {
        use aes::cipher::generic_array::typenum::Unsigned;
        use aes::cipher::{BlockCipher, NewBlockCipher};

        let mut data = blob;
        let cipher = aes::Aes192::new(GenericArray::from_slice(&key));
        let block_size = <aes::Aes192 as BlockCipher>::BlockSize::to_usize();

        assert_eq!(data.len() % block_size, 0);
        for chunk in data.chunks_exact_mut(block_size) {
            cipher.encrypt_block(GenericArray::from_mut_slice(chunk));
        }

        data
    };

    base64::encode(encrypted_blob)
}
/// Create an encrypted blob with authentication data
///
/// This has been written by reversing the instructions in the `with_blob`
/// method of `librespot_core::authentication::Credentials` structure.
Create an encrypted blob with authentication data
This has been written by reversing the instructions in the `with_blob`
method of `librespot_core::authentication::Credentials` structure.
Create an encrypted blob with authentication data This has been written by reversing the instructions in the ` with_blob ` method of ` librespot_core :: authentication :: Credentials ` structure .
pub fn build_blob(credentials: &Credentials, device_id: &str) -> String {
    let mut blob: Vec<u8> = Vec::new();
    // 'I'
    write_int(0x49, &mut blob);
    // username
    write_bytes(credentials.username.as_bytes(), &mut blob);
    // 'P'
    write_int(0x50, &mut blob);
    // auth_type
    write_int(credentials.auth_type as u32, &mut blob);
    // 'Q'
    write_int(0x51, &mut blob);
    // auth_data
    write_bytes(&credentials.auth_data, &mut blob);
    // Padding
    let n_zeros = 16 - (blob.len() % 16) - 1;
    blob.extend(vec![0; n_zeros]);
    blob.push(n_zeros as u8 + 1);
    let l = blob.len();
    for i in (0..l - 0x10).rev() {
        blob[l - i - 1] ^= blob[l - i - 0x11];
    }
    let secret = Sha1::digest(device_id.as_bytes());
    let key = {
        let mut key = [0u8; 24];
        pbkdf2::pbkdf2::<Hmac<Sha1>>(
            &secret,
            credentials.username.as_bytes(),
            0x100,
            &mut key[0..20],
        );
        let hash = Sha1::digest(&key[..20]);
        key[..20].copy_from_slice(&hash);
        key[23] = 20u8;
        key
    };
    let encrypted_blob = {
        use aes::cipher::generic_array::typenum::Unsigned;
        use aes::cipher::{BlockCipher, NewBlockCipher};
        let mut data = blob;
        let cipher = aes::Aes192::new(GenericArray::from_slice(&key));
        let block_size = <aes::Aes192 as BlockCipher>::BlockSize::to_usize();
        assert_eq!(data.len() % block_size, 0);
        for chunk in data.chunks_exact_mut(block_size) {
            cipher.encrypt_block(GenericArray::from_mut_slice(chunk));
        }
        data
    };
    base64::encode(encrypted_blob)
}
pub fn build_blob ( credentials : & Credentials , device_id : & str ) -> String { let mut blob : Vec < u8 > = Vec :: new ( ) ; // 'I' write_int ( 0x49 , & mut blob ) ; // username write_bytes ( credentials . username . as_bytes ( ) , & mut blob ) ; // 'P' write_int ( 0x50 , & mut blob ) ; // auth_type write_int ( credentials . auth_type as u32 , & mut blob ) ; // 'Q' write_int ( 0x51 , & mut blob ) ; // auth_data write_bytes ( & credentials . auth_data , & mut blob ) ; // Padding let n_zeros = 16 - ( blob . len ( ) % 16 ) - 1 ; blob . extend ( vec ! [ 0 n_zeros ] ) ; blob . push ( n_zeros as u8 + 1 ) ; let l = blob . len ( ) ; for i in ( 0 .. l - 0x10 ) . rev ( ) { blob [ l - i - 1 ] ^= blob [ l - i - 0x11 ] ; } let secret = Sha1 :: digest ( device_id . as_bytes ( ) ) ; let key = { let mut key = [ 0u8 ; 24 ] ; pbkdf2 :: pbkdf2 :: < Hmac < Sha1 > > ( & secret , credentials . username . as_bytes ( ) , 0x100 , & mut key [ 0 .. 20 ] , ) ; let hash = Sha1 :: digest ( & key [ .. 20 ] ) ; key [ .. 20 ] . copy_from_slice ( & hash ) ; key [ 23 ] = 20u8 ; key } ; let encrypted_blob = { use aes :: cipher :: generic_array :: typenum :: Unsigned ; use aes :: cipher :: { BlockCipher , NewBlockCipher } ; let mut data = blob ; let cipher = aes :: Aes192 :: new ( GenericArray :: from_slice ( & key ) ) ; let block_size = < aes :: Aes192 as BlockCipher > :: BlockSize :: to_usize ( ) ; assert_eq ! ( data len ( ) block_size 0 ) ; for chunk in data . chunks_exact_mut ( block_size ) { cipher . encrypt_block ( GenericArray :: from_mut_slice ( chunk ) ) ; } data } ; base64 :: encode ( encrypted_blob ) }
Create an encrypted blob with authentication data
This has been written by reversing the instructions in the `with_blob`
method of `librespot_core::authentication::Credentials` structure.
Create an encrypted blob with authentication data This has been written by reversing the instructions in the ` with_blob ` method of ` librespot_core :: authentication :: Credentials ` structure .
credentials
&Credentials
device_id
&str
credentials
&Credentials
device_id
&str