/****************************************************************************** * Copyright (c) 2000-2014 Ericsson Telecom AB * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html ******************************************************************************/ // This module tests the following functions: // encode_base64 // decode_base64 module Base64Testcases { import from Common all; type record of charstring RoCS; const RoCS base64table := { "A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P", "Q","R","S","T","U","V","W","X","Y","Z","a","b","c","d","e","f", "g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v", "w","x","y","z","0","1","2","3","4","5","6","7","8","9","+","/" } function f_base64_encdec_positivetest(octetstring os, boolean use_linebreaks := false) { var charstring cs :=encode_base64(os); var octetstring os2:=''O; if(use_linebreaks==false) { if(cs == encode_base64(os,use_linebreaks)){ setverdict(pass); } else { setverdict(fail); } } log("Encoded:",cs) var charstring expected := f_my_encode_base64(os); if(cs == expected) { setverdict(pass, "Encoding ok") } else { setverdict(fail,"Encoding nok") } os2 := decode_base64(cs); log(os2); if(os2 == os){ setverdict(pass, "Encoding->decoding gives back the original value") } else { setverdict(fail, "Encoding->decoding does not give back the original value") } } function f_my_encode_base64(in octetstring os, in boolean linebreaks := false) return charstring { var integer remainder := lengthof(os) mod 3; var integer extraBytes; var charstring cs_tail:=""; //this will be added to the charstring select(remainder) { case(0){ cs_tail:=""; extraBytes:=0; } case(1){ cs_tail := "=="; extraBytes:=2; os := os & '0000'O; } case(2){ cs_tail := "="; extraBytes := 1; os := os & '00'O; } } var bitstring bs := oct2bit(os); var charstring cs :=""; var integer N := lengthof(bs)-extraBytes*6; var charstring temp; var integer tempi; for( var integer i:=0; i", "{", "}", "~" }; var integer len := lengthof(rofcs); for(var integer i:=0;i", "{", "}", "~" }; var integer len := lengthof(rofcs); for(var integer i:=0;i