This is legacy code from the old encryption system, but this function is also used for backwards-compatibility in the new branch. Seems to me that it should be refactored, as you say, but I don't think is a stopper for the merge. I recommend we fix it after the merge with master is complete.