Factoring source/target into proper types, adding tests for attach enc/dec