encodeBase64 encodes s as base64 that is broken up into multiple lines as appropriate for the resulting length.
(s string)
| 267 | // encodeBase64 encodes s as base64 that is broken up into multiple lines |
| 268 | // as appropriate for the resulting length. |
| 269 | func encodeBase64(s string) string { |
| 270 | const lineLen = 70 |
| 271 | encLen := base64.StdEncoding.EncodedLen(len(s)) |
| 272 | lines := encLen/lineLen + 1 |
| 273 | buf := make([]byte, encLen*2+lines) |
| 274 | in := buf[0:encLen] |
| 275 | out := buf[encLen:] |
| 276 | base64.StdEncoding.Encode(in, []byte(s)) |
| 277 | k := 0 |
| 278 | for i := 0; i < len(in); i += lineLen { |
| 279 | j := i + lineLen |
| 280 | if j > len(in) { |
| 281 | j = len(in) |
| 282 | } |
| 283 | k += copy(out[k:], in[i:j]) |
| 284 | if lines > 1 { |
| 285 | out[k] = '\n' |
| 286 | k++ |
| 287 | } |
| 288 | } |
| 289 | return string(out[:k]) |
| 290 | } |
| 291 | |
| 292 | // This is a subset of the formats allowed by the regular expression |
| 293 | // defined at http://yaml.org/type/timestamp.html. |