github.com/iDigitalFlame/xmt@v0.5.4/c2/cfg/transform.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  // TransformB64 is a Setting that enables the Base64 Transform for the generated
    20  // Profile.
    21  const TransformB64 = cBit(0xE0)
    22  
    23  const (
    24  	valDNS      = cBit(0xE1)
    25  	valB64Shift = cBit(0xE2)
    26  )
    27  
    28  // TransformDNS returns a Setting that will apply the DNS Transform to the
    29  // generated Profile. If any DNS Domains are specified, they will be used in the
    30  // Transform.
    31  //
    32  // If a Transform Setting is already contained in the current Config Group, a
    33  // 'ErrMultipleTransforms' error will be returned when the 'Profile' function
    34  // is called.
    35  func TransformDNS(n ...string) Setting {
    36  	s := cBytes{byte(valDNS), 0}
    37  	if len(s) == 0 {
    38  		return s
    39  	}
    40  	if len(n) > 0xFF {
    41  		s[1] = 0xFF
    42  	} else {
    43  		s[1] = byte(len(n))
    44  	}
    45  	for i, c := 0, 2; i < len(n) && i < 0xFF; i++ {
    46  		v := n[i]
    47  		if len(v) > 0xFF {
    48  			v = v[:0xFF]
    49  		}
    50  		s = append(s, make([]byte, len(v)+1)...)
    51  		s[c] = byte(len(v))
    52  		c += copy(s[c+1:], v) + 1
    53  	}
    54  	return &s
    55  }
    56  
    57  // TransformB64Shift returns a Setting that will apply the Base64 Shift Transform
    58  // to the generated Profile. The specified number will be the shift index of the
    59  // Transform.
    60  //
    61  // If a Transform Setting is already contained in the current Config Group, a
    62  // 'ErrMultipleTransforms' error will be returned when the 'Profile' function is
    63  // called.
    64  func TransformB64Shift(s int) Setting {
    65  	return &cBytes{byte(valB64Shift), byte(s)}
    66  }