github.com/iDigitalFlame/xmt@v0.5.1/c2/cfg/wrap_test.go (about)

     1  // Copyright (C) 2020 - 2023 iDigitalFlame
     2  //
     3  // This program is free software: you can redistribute it and/or modify
     4  // it under the terms of the GNU General Public License as published by
     5  // the Free Software Foundation, either version 3 of the License, or
     6  // any later version.
     7  //
     8  // This program is distributed in the hope that it will be useful,
     9  // but WITHOUT ANY WARRANTY; without even the implied warranty of
    10  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    11  // GNU General Public License for more details.
    12  //
    13  // You should have received a copy of the GNU General Public License
    14  // along with this program.  If not, see <https://www.gnu.org/licenses/>.
    15  //
    16  
    17  package cfg
    18  
    19  import (
    20  	"testing"
    21  )
    22  
    23  func TestWrap(t *testing.T) {
    24  	c := Pack(
    25  		WrapAES([]byte("0123456789ABCDEF0123456789ABCDEF"), []byte("ABCDEF9876543210")),
    26  		WrapCBK(10, 20, 30, 40),
    27  		WrapCBKSize(64, 10, 20, 30, 40),
    28  	)
    29  
    30  	if _, err := c.Build(); err != nil {
    31  		t.Fatalf("TestWrap(): Build failed with error: %s!", err.Error())
    32  	}
    33  
    34  	if n := c.Len(); n != 63 {
    35  		t.Fatalf(`TestWrap(): Len returned invalid size "%d" should ne "63"!`, n)
    36  	}
    37  	if c[51] != byte(valCBK) {
    38  		t.Fatalf(`TestWrap(): Invalid byte at position "51"!`)
    39  	}
    40  	if c[53] != 10 {
    41  		t.Fatalf(`TestWrap(): Invalid byte at position "52"!`)
    42  	}
    43  	if c[57] != byte(valCBK) {
    44  		t.Fatalf(`TestWrap(): Invalid byte at position "57"!`)
    45  	}
    46  	if c[58] != 64 || c[60] != 20 {
    47  		t.Fatalf(`TestWrap(): Invalid byte at position "58:60"!`)
    48  	}
    49  }