Fix folding bug that truncated data.
Add pem test.